﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using WMS6.Common;
    using WMS6.DALFactory;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;
    using WMS6.DALFactory;

    public class ReceiptDetailBLL
    {
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private List<string> dataBaseID;
        private static readonly IFilterConfigDetailDA filterConfigDetailDA = DataAccess.CreateFilterConfigDetailDA();
        private static readonly IIntransitDA inTransitDA = DataAccess.CreateIntransitDA();
        private static readonly IIntransitDetailDA inTransitDetailDA = DataAccess.CreateIntransitDetailDA();
        private static readonly IInvHoldDA invHoldDA = DataAccess.CreateInvHoldDA();
        private static readonly IInvLotDA invLotDA = DataAccess.CreateInvLotDA();
        private static readonly IInvTransDA invTransDA = DataAccess.CreateInvTransDA();
        private static readonly IItemNoDA itemNoDA = DataAccess.CreateItemNoDA();
        private static readonly ILocationDA locationDA = DataAccess.CreateLocationDA();
        private static readonly ILotAttributeDA lotAttributeDA = DataAccess.CreateLotAttributeDA();
        private static readonly IOwnerDA ownerDA = DataAccess.CreateOwnerDA();
        private static readonly IPackDA packDA = DataAccess.CreatePackDA();
        private PubParasInfo pubParasInfo;
        private static readonly IPurchaseOrderDA purchaseOrderDA = DataAccess.CreatePurchaseOrderDA();
        private static readonly IPutawayRuleDetailDA putawayRuleDetailDA = DataAccess.CreatePutawayRuleDetailDA();
        private static readonly IReceiptDA receiptDA = DataAccess.CreateReceiptDA();
        private static readonly IReceiptDetailDA receiptDetailDA = DataAccess.CreateReceiptDetailDA();
        private List<ReceiptDetailInfo> receiptDetailInfoLists;
        private static readonly IReceiptDetailLpnDA receiptDetailLpnDA = DataAccess.CreateReceiptDetailLpnDA();
        private static readonly IReceiptValidationDA receiptValidationDA = DataAccess.CreateReceiptValidationDA();
        private static readonly ISkuDA skuDA = DataAccess.CreateSkuDA();
        private static readonly ISysSettingDA sysSettingDA = DataAccess.CreateSysSettingDA();
        private static readonly ITaskDetailDA taskDetailDA = DataAccess.CreateTaskDetailDA();
        private static readonly ITradePartnerDA tradePartnerDA = DataAccess.CreateTradePartnerDA();
        private static readonly IVendorDA vendorDA = DataAccess.CreateVendorDA();
        private static readonly IXorderDetailDA xorderDetailDA = DataAccess.CreateXorderDetailDA();
        private static readonly IXordersDA xordersDA = DataAccess.CreateXordersDA();
        private static readonly IZoneDA zoneDA = DataAccess.CreateZoneDA();

        public ReceiptDetailBLL()
        {
            this.pubParasInfo = null;
            this.receiptDetailInfoLists = new List<ReceiptDetailInfo>();
        }

        public ReceiptDetailBLL(string currentWH)
        {
            this.pubParasInfo = null;
            this.receiptDetailInfoLists = new List<ReceiptDetailInfo>();
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public ReceiptDetailBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            this.receiptDetailInfoLists = new List<ReceiptDetailInfo>();
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public string AsnDetailImportByData(string[][] ImportByData)
        {
            Exception ex;
            SysSettingInfo sysSettingInfo = sysSettingDA.GetSysSettingByID("AutomaticallyWithTheItemNo", this.dataBaseID[0], this.pubParasInfo);
            string LocIDTrue = string.Empty;
            string LocIDFalse = string.Empty;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                List<string> vendorList = new List<string>();
                List<string> locList = new List<string>();
                ReceiptInfo receiptInfo = null;
                int iLineID = 0;
                for (int i = 1; ImportByData.Length > i; i++)
                {
                    ReceiptDetailInfo receiptDetail = new ReceiptDetailInfo();
                    ReceiptLotInfo receiptLot = new ReceiptLotInfo();
                    for (int n = 0; ImportByData[i].Length > n; n++)
                    {
                        try
                        {
                            switch (ImportByData[0][n].ToUpper())
                            {
                                case "SKU":
                                {
                                    if (!string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        receiptDetail.SkuID = ImportByData[i][n];
                                    }
                                    continue;
                                }
                                case "QTY":
                                {
                                    if (!string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        receiptDetail.ExpectedQty = Convert.ToDecimal(ImportByData[i][n]);
                                    }
                                    continue;
                                }
                                case "LOC":
                                {
                                    if (!string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        receiptDetail.ToLoc = ImportByData[i][n];
                                    }
                                    continue;
                                }
                                case "CONDITION CODE":
                                {
                                    if (string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        break;
                                    }
                                    receiptDetail.ConditionCode = ImportByData[i][n];
                                    continue;
                                }
                                case "VENDOR ID":
                                {
                                    if (!string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        receiptDetail.VendorID = ImportByData[i][n];
                                    }
                                    continue;
                                }
                                case "CUBE":
                                {
                                    if (!string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        receiptDetail.Cube = Convert.ToSingle(ImportByData[i][n]);
                                    }
                                    continue;
                                }
                                case "GROSS WEIGHT":
                                {
                                    if (!string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        receiptDetail.GrossWgt = Convert.ToSingle(ImportByData[i][n]);
                                    }
                                    continue;
                                }
                                case "NET WEIGHT":
                                {
                                    if (!string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        receiptDetail.NetWgt = Convert.ToSingle(ImportByData[i][n]);
                                    }
                                    continue;
                                }
                                case "LOTTABLE01":
                                {
                                    if (string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        goto Label_040E;
                                    }
                                    receiptLot.LotAttr01 = ImportByData[i][n];
                                    continue;
                                }
                                case "LOTTABLE02":
                                {
                                    if (string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        goto Label_0447;
                                    }
                                    receiptLot.LotAttr02 = ImportByData[i][n];
                                    continue;
                                }
                                case "LOTTABLE03":
                                {
                                    if (string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        goto Label_0480;
                                    }
                                    receiptLot.LotAttr03 = ImportByData[i][n];
                                    continue;
                                }
                                case "LOTTABLE04":
                                {
                                    if (string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        goto Label_04B9;
                                    }
                                    receiptLot.LotAttr04 = ImportByData[i][n];
                                    continue;
                                }
                                case "LOTTABLE05":
                                {
                                    if (string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        goto Label_04F2;
                                    }
                                    receiptLot.LotAttr05 = ImportByData[i][n];
                                    continue;
                                }
                                case "LOTTABLE06":
                                {
                                    if (string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        goto Label_052B;
                                    }
                                    receiptLot.LotAttr06 = ImportByData[i][n];
                                    continue;
                                }
                                case "LOTTABLE07":
                                {
                                    if (string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        goto Label_0564;
                                    }
                                    receiptLot.LotAttr07 = ImportByData[i][n];
                                    continue;
                                }
                                case "LOTTABLE08":
                                {
                                    if (string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        goto Label_059D;
                                    }
                                    receiptLot.LotAttr08 = ImportByData[i][n];
                                    continue;
                                }
                                case "LOTTABLE09":
                                {
                                    if (string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        goto Label_05E6;
                                    }
                                    receiptLot.LotAttr09 = ImportByData[i][n].ToUpper().TrimEnd(new char[0]);
                                    continue;
                                }
                                case "LOTTABLE10":
                                {
                                    if (string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        goto Label_061F;
                                    }
                                    receiptLot.LotAttr10 = ImportByData[i][n];
                                    continue;
                                }
                                case "RECEIPT DATE":
                                {
                                    if (!string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        receiptLot.ReceiptDate = Convert.ToDateTime(ImportByData[i][n]);
                                    }
                                    continue;
                                }
                                case "PRODUCE DATE":
                                {
                                    if (!string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        receiptLot.ProduceDate = Convert.ToDateTime(ImportByData[i][n]);
                                    }
                                    continue;
                                }
                                case "EXPIRY DATE":
                                {
                                    if (!string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        receiptLot.ExpiryDate = Convert.ToDateTime(ImportByData[i][n]);
                                    }
                                    continue;
                                }
                                case "EXTERNAL LOT":
                                {
                                    if (!string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        receiptLot.ExternalLot = ImportByData[i][n];
                                    }
                                    continue;
                                }
                                case "CREATEDBY":
                                {
                                    if (!string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        receiptDetail.CreatedBy = ImportByData[i][n];
                                    }
                                    continue;
                                }
                                case "OWNERID":
                                {
                                    if (!string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        receiptDetail.OwnerID = ImportByData[i][n];
                                    }
                                    continue;
                                }
                                case "LPN":
                                {
                                    if (!string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        receiptDetail.LpnID = ImportByData[i][n];
                                    }
                                    continue;
                                }
                                case "ORDERID":
                                    if (string.IsNullOrEmpty(ImportByData[i][n]))
                                    {
                                        continue;
                                    }
                                    receiptDetail.ReceiptID = ImportByData[i][n];
                                    if (iLineID != 0)
                                    {
                                        goto Label_07B6;
                                    }
                                    iLineID = commonMethod.GetMaxLineID("RECEIPT_DETAIL", receiptDetail.ReceiptID, this.dataBaseID[0]);
                                    iLineID += 10;
                                    goto Label_07BF;

                                default:
                                {
                                    continue;
                                }
                            }
                            receiptDetail.ConditionCode = "OK";
                            continue;
                        Label_040E:
                            receiptLot.LotAttr01 = "";
                            continue;
                        Label_0447:
                            receiptLot.LotAttr02 = "";
                            continue;
                        Label_0480:
                            receiptLot.LotAttr03 = "";
                            continue;
                        Label_04B9:
                            receiptLot.LotAttr04 = "";
                            continue;
                        Label_04F2:
                            receiptLot.LotAttr05 = "";
                            continue;
                        Label_052B:
                            receiptLot.LotAttr06 = "";
                            continue;
                        Label_0564:
                            receiptLot.LotAttr07 = "";
                            continue;
                        Label_059D:
                            receiptLot.LotAttr08 = "";
                            continue;
                        Label_05E6:
                            receiptLot.LotAttr09 = "OK";
                            continue;
                        Label_061F:
                            receiptLot.LotAttr10 = "";
                            continue;
                        Label_07B6:
                            iLineID += 10;
                        Label_07BF:
                            receiptDetail.ReceiptLineID = iLineID;
                        }
                        catch (Exception exception1)
                        {
                            ex = exception1;
                            if (!string.IsNullOrEmpty(receiptDetail.ReceiptID))
                            {
                                throw new Exception(receiptDetail.SkuID + "（导入数据内容异常:" + ex.Message + ")");
                            }
                        }
                    }
                    receiptDetail.ReceiptLot = receiptLot;
                    if (string.IsNullOrEmpty(receiptDetail.ToLoc))
                    {
                        receiptDetail.ToLoc = "";
                    }
                    SkuInfo skuInfo = skuDA.GetSkuByID(dataBase, tran, receiptDetail.OwnerID, receiptDetail.SkuID, this.dataBaseID[0]);
                    if ((string.IsNullOrEmpty(receiptLot.LotAttr03) && ((sysSettingInfo != null) && (sysSettingInfo.Value == "Y"))) && (skuInfo != null))
                    {
                        receiptLot.LotAttr03 = skuInfo.ItemNoID;
                    }
                    receiptDetail.UpdatedBy = receiptDetail.CreatedBy;
                    receiptDetail.EffectiveDate = StrUtils.FormatDate(DateTime.Now);
                    receiptDetail.ExternReceiptID = "";
                    receiptDetail.ExternLineID = "";
                    if (string.IsNullOrEmpty(receiptDetail.LpnID))
                    {
                        receiptDetail.LpnID = "";
                    }
                    receiptDetail.PoID = "";
                    receiptDetail.AltSkuID = "";
                    receiptDetail.Status = ReceiptStatus.New;
                    receiptDetail.CaseCnt = 0M;
                    receiptDetail.InnerPack = 0M;
                    receiptDetail.Pallet = 0M;
                    receiptDetail.OtherUnit1 = 0f;
                    receiptDetail.OtherUnit2 = 0f;
                    receiptDetail.UnitPrice = 0f;
                    receiptDetail.ExtendedPrice = 0f;
                    receiptDetail.QcRequired = "";
                    receiptDetail.Length = 0f;
                    receiptDetail.Width = 0f;
                    receiptDetail.Height = 0f;
                    if (string.IsNullOrEmpty(receiptDetail.ReceiptID))
                    {
                        throw new Exception("（导入异常:主单据未保存");
                    }
                    try
                    {
                        if (receiptInfo == null)
                        {
                            receiptInfo = receiptDA.GetReceiptByID(dataBase, tran, receiptDetail.ReceiptID, this.dataBaseID[0], this.pubParasInfo);
                        }
                        if (string.IsNullOrEmpty(receiptDetail.VendorID) && !string.IsNullOrEmpty(receiptInfo.VendorID))
                        {
                            receiptDetail.VendorID = receiptInfo.VendorID;
                        }
                        if (!ownerDA.CheckTradePartnerIDUnique(receiptDetail.OwnerID, this.dataBaseID[0]))
                        {
                            throw new Exception(receiptDetail.SkuID + "( 货主" + receiptDetail.OwnerID + ")不存在,导入失败);");
                        }
                        if (!commonMethod.CheckAuthorizationOwnerByUserID(this.pubParasInfo.UserID, receiptDetail.OwnerID))
                        {
                            throw new Exception(receiptDetail.SkuID + "( 货主" + receiptDetail.OwnerID + ")没有权限,导入失败);");
                        }
                        if (skuInfo == null)
                        {
                            throw new Exception(receiptDetail.SkuID + "( 货主" + receiptDetail.OwnerID + "  Sku(货品 " + receiptDetail.SkuID + ")不存在,导入失败");
                        }
                        if (skuInfo.IsActive != "Y")
                        {
                            throw new Exception(receiptDetail.SkuID + "( 货主" + receiptDetail.OwnerID + "  Sku(货品 " + receiptDetail.SkuID + ")未启用,导入失败");
                        }
                        receiptDetail.UnitPrice = Convert.ToSingle(skuInfo.CostPrice);
                        receiptDetail.ExtendedPrice = Convert.ToSingle(skuInfo.CostPrice) * Convert.ToSingle(receiptDetail.ExpectedQty);
                        if (!string.IsNullOrEmpty(receiptDetail.VendorID))
                        {
                            if (!vendorDA.CheckVendorIDUnique(dataBase, tran, receiptDetail.VendorID, this.dataBaseID[0]))
                            {
                                if (!vendorList.Contains(receiptDetail.VendorID))
                                {
                                    vendorList.Add(receiptDetail.VendorID);
                                }
                                continue;
                            }
                            if (!vendorDA.CheckAuthorizationVendorIDUserID(dataBase, tran, receiptDetail.VendorID, this.dataBaseID[0], this.pubParasInfo))
                            {
                                if (!vendorList.Contains(receiptDetail.VendorID))
                                {
                                    vendorList.Add(receiptDetail.VendorID);
                                }
                                continue;
                            }
                            VendorInfo vendorInfo = vendorDA.GetVendorByID(dataBase, tran, receiptDetail.VendorID, this.dataBaseID[0], this.pubParasInfo);
                            receiptDetail.VendorName = vendorInfo.Company;
                        }
                        if (!string.IsNullOrEmpty(receiptDetail.ToLoc) && !locationDA.CheckLocationIDUnique(dataBase, tran, receiptDetail.ToLoc, this.dataBaseID[0]))
                        {
                            if (!locList.Contains(receiptDetail.ToLoc))
                            {
                                locList.Add(receiptDetail.ToLoc);
                            }
                        }
                        else
                        {
                            receiptDetail.PackID = skuInfo.PackID;
                            PackInfo packInfo = packDA.GetPackByID(dataBase, tran, receiptDetail.PackID, this.dataBaseID[0]);
                            receiptDetail.UomID = packInfo.PackUom1;
                            if (receiptDetailDA.InsertReceiptDetail(dataBase, tran, receiptDetail, this.dataBaseID[0]) > 0)
                            {
                                LocIDTrue = LocIDTrue + receiptDetail.SkuID + ";";
                            }
                        }
                    }
                    catch (Exception exception2)
                    {
                        ex = exception2;
                        if (!string.IsNullOrEmpty(receiptDetail.SkuID))
                        {
                            throw new Exception(receiptDetail.SkuID + "（交互异常:" + ex.Message + "）");
                        }
                    }
                }
                if (vendorList.Count > 0)
                {
                    foreach (string item in vendorList)
                    {
                        throw new Exception(item + "(导入数据Vendor ID(供应商)不存在)");
                    }
                }
                if (locList.Count > 0)
                {
                    foreach (string item in locList)
                    {
                        throw new Exception(item + "(导入数据Loc(货位)不存在)");
                    }
                }
                tran.Commit();
            }
            catch (Exception exception3)
            {
                ex = exception3;
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return LocIDFalse;
        }

        public string AutoPutAway(string receiptID, List<string> receiptLineID)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            string updatedBy = this.pubParasInfo.UserID;
            try
            {
                ReceiptInfo receiptInfo = receiptDA.GetReceiptByID(receiptID, whLoginID, this.pubParasInfo);
                List<ReceiptHistoryInfo> receiptHistoryInfo = null;
                string receiptLineIDWhere = "RD.RECEIPT_LINE_ID IN(";
                foreach (string lineID in receiptLineID)
                {
                    receiptLineIDWhere = receiptLineIDWhere + "'" + lineID + "',";
                }
                receiptLineIDWhere = receiptLineIDWhere.Substring(0, receiptLineIDWhere.Length - 1) + ") ";
                if (receiptInfo.IsPalletized == "Y")
                {
                    receiptHistoryInfo = receiptDetailLpnDA.GetReceiptHistoryInfoListByWhere(receiptID, receiptLineIDWhere, whLoginID);
                }
                else
                {
                    receiptHistoryInfo = receiptDetailDA.GetReceiptHistoryInfoListByWhere(receiptID, receiptLineIDWhere, whLoginID);
                }
                if ((receiptHistoryInfo != null) && (receiptHistoryInfo.Count > 0))
                {
                    InventoryMgtBLL inventoryMgtBll = new InventoryMgtBLL();
                    for (int i = 0; i < receiptHistoryInfo.Count; i++)
                    {
                        temp = temp + this.GeneratePutAwayByReceiptHistory(receiptHistoryInfo[i], inventoryMgtBll, updatedBy, whLoginID) + ",";
                    }
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return (string.IsNullOrEmpty(temp) ? "" : temp.Substring(0, temp.Length - 1));
        }

        public string BatchReceiving(string receiptID, List<string> receiptLineID)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            string updatedBy = this.pubParasInfo.UserID;
            try
            {
                ReceiptInfo receiptInfo = receiptDA.GetReceiptByID(receiptID, whLoginID, this.pubParasInfo);
                SysSettingInfo sysSettinginfo = sysSettingDA.GetSysSettingByID("ReceivingCheckSAPValidation", whLoginID, this.pubParasInfo);
                if (((sysSettinginfo != null) && (sysSettinginfo.Value == "Y")) && (((receiptInfo != null) && ((receiptInfo.ReceiptType.ToUpper() == "NORMAL") || (receiptInfo.ReceiptType.ToUpper() == "CROSSDOCK"))) && (receiptInfo.SAPAuthentication.ToUpper() != "Y")))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F4200_025", this.pubParasInfo.UserLanguage);
                }
                List<ReceiptDetailInfo> tempReceiptDetailInfos = null;
                string where = "(RD.STATUS = 'New' OR RD.STATUS = 'InReceiving') ";
                if (receiptInfo.IsPalletized == "Y")
                {
                    tempReceiptDetailInfos = receiptDetailLpnDA.GetReceiptDetailListByWhere(receiptID, where, whLoginID, this.pubParasInfo);
                }
                else
                {
                    tempReceiptDetailInfos = receiptDetailDA.GetReceiptDetailListByWhere(receiptID, where, whLoginID, this.pubParasInfo);
                }
                if ((tempReceiptDetailInfos != null) && (tempReceiptDetailInfos.Count > 0))
                {
                    InboundHelper inboundHelper = new InboundHelper();
                    Dictionary<string, SkuInfo> skuInfoList = new Dictionary<string, SkuInfo>();
                    Dictionary<string, ReceiptValidationInfo> receiptValidationInfoList = new Dictionary<string, ReceiptValidationInfo>();
                    for (int i = 0; i < tempReceiptDetailInfos.Count; i++)
                    {
                        for (int j = 0; j < receiptLineID.Count; j++)
                        {
                            if ((tempReceiptDetailInfos[i].ReceiptLineID.ToString() == receiptLineID[j]) && (tempReceiptDetailInfos[i].Status != ReceiptStatus.ReceivedComplete))
                            {
                                SkuInfo skuInfo = null;
                                if (skuInfoList.ContainsKey(tempReceiptDetailInfos[i].OwnerID + tempReceiptDetailInfos[i].SkuID))
                                {
                                    skuInfo = skuInfoList[tempReceiptDetailInfos[i].OwnerID + tempReceiptDetailInfos[i].SkuID];
                                }
                                else
                                {
                                    skuInfo = skuDA.GetSkuByID(tempReceiptDetailInfos[i].OwnerID, tempReceiptDetailInfos[i].SkuID, whLoginID);
                                    skuInfoList.Add(tempReceiptDetailInfos[i].OwnerID + tempReceiptDetailInfos[i].SkuID, skuInfo);
                                }
                                ReceiptValidationInfo receiptValidationInfo = null;
                                if (receiptValidationInfoList.ContainsKey(skuInfo.ReceiptValidationID))
                                {
                                    receiptValidationInfo = receiptValidationInfoList[skuInfo.ReceiptValidationID];
                                }
                                else
                                {
                                    receiptValidationInfo = receiptValidationDA.GetReceiptValidationByID(skuInfo.ReceiptValidationID, whLoginID);
                                    receiptValidationInfoList.Add(skuInfo.ReceiptValidationID, receiptValidationInfo);
                                }
                                tempReceiptDetailInfos[i].ToLpnID = tempReceiptDetailInfos[i].LpnID;
                                this.ReceivingValidate(tempReceiptDetailInfos[i], receiptValidationInfo, whLoginID);
                                tempReceiptDetailInfos[i] = this.InitReceiptDetailInfo4Receiving(tempReceiptDetailInfos[i], inboundHelper, whLoginID);
                                if (skuInfo.ShelfLifeIndicator == "Y")
                                {
                                    DateTime CS00003;
                                    if (skuInfo.ShelfLifeCodeType.ToUpper() == "E")
                                    {
                                        CS00003 = tempReceiptDetailInfos[i].ReceiptLot.ExpiryDate;
                                        if ((!string.IsNullOrEmpty(CS00003.ToString()) && (tempReceiptDetailInfos[i].ReceiptLot.ExpiryDate != new DateTime())) && (tempReceiptDetailInfos[i].ReceiptLot.ReceiptDate.AddDays((double) skuInfo.ShelfLifeOnReceiving) > tempReceiptDetailInfos[i].ReceiptLot.ExpiryDate))
                                        {
                                            throw new Exception("该行项" + tempReceiptDetailInfos[i].ReceiptLineID.ToString() + "入库保质期不满足!");
                                        }
                                    }
                                    else
                                    {
                                        CS00003 = tempReceiptDetailInfos[i].ReceiptLot.ProduceDate;
                                        if ((!string.IsNullOrEmpty(CS00003.ToString()) && (tempReceiptDetailInfos[i].ReceiptLot.ProduceDate != new DateTime())) && (tempReceiptDetailInfos[i].ReceiptLot.ProduceDate.AddDays((double) skuInfo.ShelfLifeOnReceiving) > tempReceiptDetailInfos[i].ReceiptLot.ReceiptDate))
                                        {
                                            throw new Exception("该行项" + tempReceiptDetailInfos[i].ReceiptLineID.ToString() + "入库保质期不满足!");
                                        }
                                    }
                                }
                                string toLoc = "Stage";
                                if (!string.IsNullOrEmpty(tempReceiptDetailInfos[i].ToLoc))
                                {
                                    toLoc = tempReceiptDetailInfos[i].ToLoc;
                                }
                                else if (skuInfo != null)
                                {
                                    ZoneInfo zoneInfo = zoneDA.GetZoneByID(skuInfo.ZoneID, whLoginID);
                                    if (zoneInfo != null)
                                    {
                                        toLoc = string.IsNullOrEmpty(zoneInfo.InLoc) ? "Stage" : zoneInfo.InLoc;
                                    }
                                }
                                tempReceiptDetailInfos[i].ToLoc = toLoc;
                                try
                                {
                                    this.ExecuteReceiving(receiptInfo, tempReceiptDetailInfos[i]);
                                }
                                catch
                                {
                                    temp = temp + tempReceiptDetailInfos[i].ReceiptLineID.ToString() + ",";
                                }
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            if (!string.IsNullOrEmpty(temp))
            {
                return temp.Substring(0, temp.Length - 1);
            }
            return temp;
        }

        public bool CheckDimRestrictionByPAStratety(DataBase dataBase, DbTransaction tran, string suggestLoc, SkuInfo skuInfo, GenPutawayLocInfo genPutawayLocInfo, PutawayRuleDetailInfo putAwayRuleDetailInfo, string whLoginID)
        {
            bool fit = false;
            try
            {
                if (!this.SwitchDimRestriction(dataBase, tran, suggestLoc, skuInfo, genPutawayLocInfo, putAwayRuleDetailInfo.DimRestriction01, whLoginID))
                {
                    return fit;
                }
                if (!this.SwitchDimRestriction(dataBase, tran, suggestLoc, skuInfo, genPutawayLocInfo, putAwayRuleDetailInfo.DimRestriction02, whLoginID))
                {
                    return fit;
                }
                if (!this.SwitchDimRestriction(dataBase, tran, suggestLoc, skuInfo, genPutawayLocInfo, putAwayRuleDetailInfo.DimRestriction03, whLoginID))
                {
                    return fit;
                }
                if (!this.SwitchDimRestriction(dataBase, tran, suggestLoc, skuInfo, genPutawayLocInfo, putAwayRuleDetailInfo.DimRestriction04, whLoginID))
                {
                    return fit;
                }
                if (!this.SwitchDimRestriction(dataBase, tran, suggestLoc, skuInfo, genPutawayLocInfo, putAwayRuleDetailInfo.DimRestriction05, whLoginID))
                {
                    return fit;
                }
                if (this.SwitchDimRestriction(dataBase, tran, suggestLoc, skuInfo, genPutawayLocInfo, putAwayRuleDetailInfo.DimRestriction06, whLoginID))
                {
                    fit = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return fit;
        }

        public bool CheckIsMulitLotCanPutAway2Loc(DataSet ds, GenPutawayLocInfo genPutawayLocInfo, bool temp)
        {
            if (ds.Tables[0].Rows.Count > 1)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (decimal.Parse(ds.Tables[0].Rows[i]["QTY"].ToString()) == 0M)
                    {
                        temp = true;
                    }
                    else if (ds.Tables[0].Rows[i]["LOT"].ToString().ToUpper() == genPutawayLocInfo.Lot.ToUpper())
                    {
                        temp = true;
                    }
                    else
                    {
                        temp = false;
                        return temp;
                    }
                }
                return temp;
            }
            if (ds.Tables[0].Rows[0]["LOT"].ToString().ToUpper() == genPutawayLocInfo.Lot.ToUpper())
            {
                temp = true;
                return temp;
            }
            if (decimal.Parse(ds.Tables[0].Rows[0]["QTY"].ToString()) == 0M)
            {
                temp = true;
                return temp;
            }
            temp = false;
            return temp;
        }

        public bool CheckIsMulitLotCanPutAway2Loc(DataSet ds, ReceiptDetailInfo receiptDetailInfo, bool temp)
        {
            if (ds.Tables[0].Rows.Count > 1)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (decimal.Parse(ds.Tables[0].Rows[i]["QTY"].ToString()) == 0M)
                    {
                        temp = true;
                    }
                    else if (ds.Tables[0].Rows[i]["LOT"].ToString().ToUpper() == receiptDetailInfo.ToLot.ToUpper())
                    {
                        temp = true;
                    }
                    else
                    {
                        temp = false;
                        return temp;
                    }
                }
                return temp;
            }
            if (ds.Tables[0].Rows[0]["LOT"].ToString().ToUpper() == receiptDetailInfo.ToLot.ToUpper())
            {
                temp = true;
                return temp;
            }
            if (decimal.Parse(ds.Tables[0].Rows[0]["QTY"].ToString()) == 0M)
            {
                temp = true;
                return temp;
            }
            temp = false;
            return temp;
        }

        public bool CheckIsMulitSkuCanPutAway2Loc(DataSet ds, GenPutawayLocInfo genPutawayLocInfo, bool temp)
        {
            if (ds.Tables[0].Rows.Count > 1)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (decimal.Parse(ds.Tables[0].Rows[i]["QTY"].ToString()) == 0M)
                    {
                        temp = true;
                    }
                    else if ((ds.Tables[0].Rows[i]["OWNER_ID"].ToString().ToUpper() == genPutawayLocInfo.OwnerID.ToUpper()) && (ds.Tables[0].Rows[i]["SKU_ID"].ToString().ToUpper() == genPutawayLocInfo.SkuID.ToUpper()))
                    {
                        temp = true;
                    }
                    else
                    {
                        temp = false;
                        return temp;
                    }
                }
                return temp;
            }
            if ((ds.Tables[0].Rows[0]["OWNER_ID"].ToString().ToUpper() == genPutawayLocInfo.OwnerID.ToUpper()) && (ds.Tables[0].Rows[0]["SKU_ID"].ToString().ToUpper() == genPutawayLocInfo.SkuID.ToUpper()))
            {
                temp = true;
                return temp;
            }
            if (decimal.Parse(ds.Tables[0].Rows[0]["QTY"].ToString()) == 0M)
            {
                temp = true;
                return temp;
            }
            temp = false;
            return temp;
        }

        public bool CheckIsMulitSkuCanPutAway2Loc(DataSet ds, ReceiptDetailInfo receiptDetailInfo, bool temp)
        {
            if (ds.Tables[0].Rows.Count > 1)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (decimal.Parse(ds.Tables[0].Rows[i]["QTY"].ToString()) == 0M)
                    {
                        temp = true;
                    }
                    else if ((ds.Tables[0].Rows[i]["OWNER_ID"].ToString().ToUpper() == receiptDetailInfo.OwnerID.ToUpper()) && (ds.Tables[0].Rows[i]["SKU_ID"].ToString().ToUpper() == receiptDetailInfo.SkuID.ToUpper()))
                    {
                        temp = true;
                    }
                    else
                    {
                        temp = false;
                        return temp;
                    }
                }
                return temp;
            }
            if ((ds.Tables[0].Rows[0]["OWNER_ID"].ToString().ToUpper() == receiptDetailInfo.OwnerID.ToUpper()) && (ds.Tables[0].Rows[0]["SKU_ID"].ToString().ToUpper() == receiptDetailInfo.SkuID.ToUpper()))
            {
                temp = true;
                return temp;
            }
            if (decimal.Parse(ds.Tables[0].Rows[0]["QTY"].ToString()) == 0M)
            {
                temp = true;
                return temp;
            }
            temp = false;
            return temp;
        }

        public bool CheckLocByLocFilter(DataBase dataBase, DbTransaction tran, string suggestLoc, string filterName, GenPutawayLocInfo genPutawayLocInfo, string whLoginID)
        {
            bool pass = true;
            FilterConfigDetailInfo filterConfigDetailInfo = filterConfigDetailDA.GetFilterConfigDetailByID(dataBase, tran, FilterRecordType.LocSel, filterName, whLoginID);
            if ((filterConfigDetailInfo != null) && (receiptDetailDA.CheckLocByLocFilter(dataBase, tran, suggestLoc, genPutawayLocInfo.ReceiptID, genPutawayLocInfo.ReceiptLineID, filterConfigDetailInfo.FilterStatement, whLoginID) == null))
            {
                pass = false;
            }
            return pass;
        }

        public bool CheckLocStatusLimitByPAStrategy(DataBase dataBase, DbTransaction tran, string suggestLoc, PutawayRuleDetailInfo putAwayRuleDetailInfo, GenPutawayLocInfo genPutawayLocInfo, string whLoginID)
        {
            bool fit = false;
            if (this.SwitchLocStatusLimit(dataBase, tran, suggestLoc, "10", !string.IsNullOrEmpty(putAwayRuleDetailInfo.LocStateRestriction01), genPutawayLocInfo, whLoginID))
            {
                if (!this.SwitchLocStatusLimit(dataBase, tran, suggestLoc, "20", !string.IsNullOrEmpty(putAwayRuleDetailInfo.LocStateRestriction02), genPutawayLocInfo, whLoginID))
                {
                    return fit;
                }
                if (!this.SwitchLocStatusLimit(dataBase, tran, suggestLoc, "30", !string.IsNullOrEmpty(putAwayRuleDetailInfo.LocStateRestriction03), genPutawayLocInfo, whLoginID))
                {
                    return fit;
                }
                if (!this.SwitchLocStatusLimit(dataBase, tran, suggestLoc, "40", !string.IsNullOrEmpty(putAwayRuleDetailInfo.LocStateRestriction04), genPutawayLocInfo, whLoginID))
                {
                    return fit;
                }
                if (this.SwitchLocStatusLimit(dataBase, tran, suggestLoc, "50", !string.IsNullOrEmpty(putAwayRuleDetailInfo.LocStateRestriction05), genPutawayLocInfo, whLoginID))
                {
                    fit = true;
                }
            }
            return fit;
        }

        public bool CheckMandatoryLotAttribute(ReceiptDetailInfo receiptDetailInfo, string whLoginID)
        {
            bool isInput = false;
            List<string> inputLotAttr = new List<string> {
                receiptDetailInfo.ReceiptLot.ExternalLot.Trim(),
                receiptDetailInfo.ReceiptLot.ProduceDate.ToString().Trim()
            };
            DateTime CS00001 = receiptDetailInfo.ReceiptLot.ExpiryDate;
            inputLotAttr.Add(CS00001.ToString().Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr01.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr02.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr03.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr04.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr05.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr06.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr07.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr08.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr09.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr10.Trim());
            DataSet ds = receiptDetailDA.GetMandatoryLotAttributeInfo(receiptDetailInfo.OwnerID, receiptDetailInfo.SkuID, whLoginID);
            if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
            {
                for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
                {
                    if (ds.Tables[0].Rows[0][i].ToString() == "Y")
                    {
                        if ((i == 1) || (i == 2))
                        {
                            CS00001 = new DateTime();
                            isInput = Convert.ToDateTime(inputLotAttr[i]) == CS00001;
                        }
                        else
                        {
                            isInput = string.IsNullOrEmpty(inputLotAttr[i]);
                        }
                        if (isInput)
                        {
                            break;
                        }
                    }
                }
            }
            return !isInput;
        }

        private bool CheckMandatoryLotAttribute(DataBase dataBase, DbTransaction tran, ReceiptDetailInfo receiptDetailInfo, string whLoginID)
        {
            bool isInput = false;
            List<string> inputLotAttr = new List<string> {
                receiptDetailInfo.ReceiptLot.ExternalLot.Trim(),
                receiptDetailInfo.ReceiptLot.ProduceDate.ToString().Trim()
            };
            DateTime CS00001 = receiptDetailInfo.ReceiptLot.ExpiryDate;
            inputLotAttr.Add(CS00001.ToString().Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr01.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr02.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr03.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr04.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr05.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr06.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr07.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr08.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr09.Trim());
            inputLotAttr.Add(receiptDetailInfo.ReceiptLot.LotAttr10.Trim());
            DataSet ds = receiptDetailDA.GetMandatoryLotAttributeInfo(dataBase, tran, receiptDetailInfo.OwnerID, receiptDetailInfo.SkuID, whLoginID);
            if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
            {
                for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
                {
                    if (ds.Tables[0].Rows[0][i].ToString() == "Y")
                    {
                        if ((i == 0) || (i == 1))
                        {
                            CS00001 = new DateTime();
                            isInput = Convert.ToDateTime(inputLotAttr[i]) == CS00001;
                        }
                        else
                        {
                            isInput = string.IsNullOrEmpty(inputLotAttr[i]);
                        }
                        if (isInput)
                        {
                            break;
                        }
                    }
                }
            }
            return !isInput;
        }

        public string CheckSkuIDExist(string orderID, string skuID)
        {
            string whLoginID = this.dataBaseID[0];
            if (receiptDetailDA.CheckReceiptDetailSkuExist(orderID, skuID, whLoginID))
            {
                return "Y";
            }
            return "N";
        }

        public string ConfirmPutAway(List<PutawayDetailInfo> putawayDetailInfo)
        {
            int temp = 0;
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                InboundHelper inboundHelper = new InboundHelper();
                InventoryMgtBLL inventoryMgtBll = new InventoryMgtBLL(this.pubParasInfo);
                ILocationDA locationDA = DataAccess.CreateLocationDA();
                InvMovesInfo invMovesInfo = null;
                for (int i = 0; i < putawayDetailInfo.Count; i++)
                {
                    if (!locationDA.CheckLocationIDUnique(dataBase, tran, putawayDetailInfo[i].FinalLoc, whLoginID))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F4200_014", this.pubParasInfo.UserLanguage);
                    }
                    ReceiptDetailInfo receiptDetailInfo = receiptDetailDA.GetReceiptDetailByID(dataBase, tran, putawayDetailInfo[i].ReceiptID, putawayDetailInfo[i].ReceiptLineID, whLoginID, this.pubParasInfo);
                    LotAttributeInfo lotAttr = lotAttributeDA.GetLotAttributeByID(dataBase, tran, putawayDetailInfo[i].LotID, whLoginID);
                    if (lotAttr != null)
                    {
                        ReceiptLotInfo receiptLotInfo = new ReceiptLotInfo {
                            LotAttr01 = lotAttr.LotAttr01,
                            LotAttr02 = lotAttr.LotAttr02,
                            LotAttr03 = lotAttr.LotAttr03,
                            LotAttr04 = lotAttr.LotAttr04,
                            LotAttr05 = lotAttr.LotAttr05,
                            LotAttr06 = lotAttr.LotAttr06,
                            LotAttr07 = lotAttr.LotAttr07,
                            LotAttr08 = lotAttr.LotAttr08,
                            LotAttr09 = lotAttr.LotAttr09,
                            LotAttr10 = lotAttr.LotAttr10,
                            ProduceDate = lotAttr.ProduceDate,
                            ExpiryDate = lotAttr.ExpiryDate,
                            ExternalLot = lotAttr.ExternalLot,
                            VendorID = lotAttr.VendorID,
                            ReceiptDate = lotAttr.ReceiptDate
                        };
                        receiptDetailInfo.ReceiptLot = receiptLotInfo;
                    }
                    receiptDetailInfo.ReceivedQty = putawayDetailInfo[i].Qty;
                    receiptDetailInfo.UomID = putawayDetailInfo[i].UomID;
                    receiptDetailInfo.FromLoc = receiptDetailInfo.ToLoc;
                    receiptDetailInfo.FromLpnID = receiptDetailInfo.ToLpnID;
                    receiptDetailInfo.ToLoc = putawayDetailInfo[i].FinalLoc;
                    receiptDetailInfo.ToLpnID = putawayDetailInfo[i].LpnID;
                    receiptDetailInfo.UpdatedBy = putawayDetailInfo[i].UpdatedBy;
                    string toTransID = inboundHelper.InsertInvTrans(dataBase, tran, receiptDetailInfo, TransType.Movement, TransSourceType.PutawayMove, TransStatus.OK, putawayDetailInfo[i].TaskDetailID, 0, whLoginID);
                    temp = receiptDetailDA.UpdatePutawayTaskDetailStatus(dataBase, tran, putawayDetailInfo[i].TaskDetailID, TaskStatus.Completed, putawayDetailInfo[i].FinalLoc, toTransID, this.pubParasInfo.UserID, whLoginID);
                    invMovesInfo = new InvMovesInfo(putawayDetailInfo[i].OwnerID, putawayDetailInfo[i].SkuID, putawayDetailInfo[i].LotID, putawayDetailInfo[i].FromLoc, putawayDetailInfo[i].FromLpnID, putawayDetailInfo[i].OwnerID, putawayDetailInfo[i].SkuID, putawayDetailInfo[i].LotID, putawayDetailInfo[i].FinalLoc, putawayDetailInfo[i].LpnID, putawayDetailInfo[i].Qty, putawayDetailInfo[i].PackID, putawayDetailInfo[i].UomID, putawayDetailInfo[i].Qty, putawayDetailInfo[i].PackID, putawayDetailInfo[i].UomID, this.pubParasInfo.UserID);
                    inventoryMgtBll.UpdateInvLotLocLpn4Moves(dataBase, tran, invMovesInfo, InvMoveType.Move, whLoginID);
                    inventoryMgtBll.UpdateInvSkuLoc4Moves(dataBase, tran, invMovesInfo, InvMoveType.Move, whLoginID);
                    inventoryMgtBll.UpdateInvSkuLocExceptedQty(dataBase, tran, putawayDetailInfo[i].OwnerID, putawayDetailInfo[i].SkuID, putawayDetailInfo[i].SuggestLoc, putawayDetailInfo[i].Qty * -1M, this.pubParasInfo.UserID, whLoginID);
                    inventoryMgtBll.UpdateInvLotLocLpnPendingQty(dataBase, tran, putawayDetailInfo[i].LotID, putawayDetailInfo[i].FromLoc, putawayDetailInfo[i].FromLpnID, putawayDetailInfo[i].Qty * -1M, this.pubParasInfo.UserID, whLoginID);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                conn.Close();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return temp.ToString();
        }

        private ReceiptDetailInfo ConvertToAnotherReceiptDetailInfo(ReceiptDetailInfo receiptDetailinfo)
        {
            return new ReceiptDetailInfo { 
                WhID = receiptDetailinfo.WhID, ReceiptID = receiptDetailinfo.ReceiptID, ReceiptLineID = receiptDetailinfo.ReceiptLineID, ExternReceiptID = receiptDetailinfo.ExternReceiptID, ExternLineID = receiptDetailinfo.ExternLineID, OwnerID = receiptDetailinfo.OwnerID, PoID = receiptDetailinfo.PoID, PoLineID = receiptDetailinfo.PoLineID, TariffID = receiptDetailinfo.TariffID, SkuID = receiptDetailinfo.SkuID, SkuDescr = receiptDetailinfo.SkuDescr, AltSkuID = receiptDetailinfo.AltSkuID, LpnID = receiptDetailinfo.LpnID, CaseID = receiptDetailinfo.CaseID, Status = receiptDetailinfo.Status, StatusD = receiptDetailinfo.StatusD, 
                ReceivedDate = receiptDetailinfo.ReceivedDate, ExpectedQty = receiptDetailinfo.ExpectedQty, AdjustedQty = receiptDetailinfo.AdjustedQty, ReceivedQty = receiptDetailinfo.ReceivedQty, RejectedQty = receiptDetailinfo.RejectedQty, UomID = receiptDetailinfo.UomID, PackID = receiptDetailinfo.PackID, ToLoc = receiptDetailinfo.ToLoc, ToLot = receiptDetailinfo.ToLot, ToLpnID = receiptDetailinfo.ToLpnID, ConditionCode = receiptDetailinfo.ConditionCode, ReceiptLot = receiptDetailinfo.ReceiptLot, CaseCnt = receiptDetailinfo.CaseCnt, InnerPack = receiptDetailinfo.InnerPack, Pallet = receiptDetailinfo.Pallet, Cube = receiptDetailinfo.Cube, 
                GrossWgt = receiptDetailinfo.GrossWgt, NetWgt = receiptDetailinfo.NetWgt, Length = receiptDetailinfo.Length, Width = receiptDetailinfo.Width, Height = receiptDetailinfo.Height, OtherUnit1 = receiptDetailinfo.OtherUnit1, OtherUnit2 = receiptDetailinfo.OtherUnit2, UnitPrice = receiptDetailinfo.UnitPrice, EffectiveDate = receiptDetailinfo.EffectiveDate, Udf1 = receiptDetailinfo.Udf1, Udf2 = receiptDetailinfo.Udf2, Udf3 = receiptDetailinfo.Udf3, Udf4 = receiptDetailinfo.Udf4, Udf5 = receiptDetailinfo.Udf5, Udf6 = receiptDetailinfo.Udf6, Udf7 = receiptDetailinfo.Udf7, 
                Udf8 = receiptDetailinfo.Udf8, Udf9 = receiptDetailinfo.Udf9, Udf10 = receiptDetailinfo.Udf10, ReasonCode = receiptDetailinfo.ReasonCode, PalletID = receiptDetailinfo.PalletID, Type = receiptDetailinfo.Type, ReturnType = receiptDetailinfo.ReturnType, ReturnReason = receiptDetailinfo.ReturnReason, DispositionType = receiptDetailinfo.DispositionType, DispositionCode = receiptDetailinfo.DispositionCode, ReturnCondition = receiptDetailinfo.ReturnCondition, QcRequired = receiptDetailinfo.QcRequired, QcInspectedQty = receiptDetailinfo.QcInspectedQty, QcRejectedQty = receiptDetailinfo.QcRejectedQty, QcRejReason = receiptDetailinfo.QcRejReason, QcStatus = receiptDetailinfo.QcStatus, 
                QcUser = receiptDetailinfo.QcUser, QcAutoAdjust = receiptDetailinfo.QcAutoAdjust, Rma = receiptDetailinfo.Rma, VendorID = receiptDetailinfo.VendorID, VendorName = receiptDetailinfo.VendorName, MatchLottable = receiptDetailinfo.MatchLottable, CrossDockID = receiptDetailinfo.CrossDockID, Remark = receiptDetailinfo.Remark, CreatedBy = receiptDetailinfo.CreatedBy, CreatedDate = receiptDetailinfo.CreatedDate, UpdatedBy = receiptDetailinfo.UpdatedBy, UpdatedDate = receiptDetailinfo.UpdatedDate, FromLoc = receiptDetailinfo.FromLoc, FromLpnID = receiptDetailinfo.FromLpnID, IsGenPutAway = receiptDetailinfo.IsGenPutAway, IsPalletized = receiptDetailinfo.IsPalletized, 
                HadReceivedQty = receiptDetailinfo.HadReceivedQty
             };
        }

        public string DeleteReceiptDetail(List<string> receiptID, List<string> receiptLineID)
        {
            string whLoginID = this.dataBaseID[0];
            string temp = string.Empty;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                int i;
                if (receiptID.Count != receiptLineID.Count)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F4200_012", this.pubParasInfo.UserLanguage);
                }
                List<ReceiptDetailInfo> receiptDetailInfos = new List<ReceiptDetailInfo>();
                ReceiptDetailInfo receiptDetailInfo = null;
                for (i = 0; i < receiptID.Count; i++)
                {
                    receiptDetailInfo = receiptDetailDA.GetReceiptDetailByID(dataBase, tran, receiptID[i], receiptLineID[i], whLoginID, this.pubParasInfo);
                    receiptDetailInfos.Add(receiptDetailInfo);
                }
                AuditDataBLL auditDataBLL = new AuditDataBLL();
                if (receiptDetailDA.DeleteReceiptDetail(dataBase, tran, receiptID, receiptLineID, whLoginID) > 0)
                {
                    for (i = 0; i < receiptID.Count; i++)
                    {
                        auditDataBLL.InsertAuditData<ReceiptDetailInfo>(dataBase, tran, receiptDetailInfos[i], null, AuditAction.Delete, this.pubParasInfo.UserID, "RECEIPT_DETAIL", whLoginID);
                        string CS00002 = temp;
                        temp = CS00002 + receiptID[i] + " , " + receiptLineID[i] + " ; ";
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            if (temp.Length > 0)
            {
                return temp.Substring(0, temp.Length - 1);
            }
            return "";
        }

        public string ExecuteReceiving(ReceiptDetailInfo receiptDetailInfo)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            this.ReceivingValidate(receiptDetailInfo, whLoginID);
            ReceiptInfo receipt = receiptDA.GetReceiptByID(receiptDetailInfo.ReceiptID, whLoginID, this.pubParasInfo);
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                temp = this.ExecuteReceiving(dataBase, tran, receipt, receiptDetailInfo, whLoginID);
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                this.receiptDetailInfoLists.Clear();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            SysSettingInfo sysSettinginfo = sysSettingDA.GetSysSettingByID("CEAWebService", whLoginID, this.pubParasInfo);
            if (sysSettinginfo != null)
            {
                if (!(sysSettinginfo.Value == "Y"))
                {
                    return temp;
                }
                if (this.receiptDetailInfoLists.Count <= 0)
                {
                    return temp;
                }
                ReceiptInfo receiptInfo = receiptDA.GetReceiptByID(this.receiptDetailInfoLists[0].ReceiptID, whLoginID, this.pubParasInfo);
                foreach (ReceiptDetailInfo info in this.receiptDetailInfoLists)
                {
                    info.Udf3 = receiptInfo.Udf2;
                    info.Udf4 = receiptInfo.Udf3;
                }
                receiptInfo.Udf10 = new CEABLL(this.pubParasInfo).ReceivingPosting(this.receiptDetailInfoLists);
                if (!string.IsNullOrEmpty(receiptInfo.Udf10))
                {
                    receiptDA.UpdateReceipt(receiptInfo, whLoginID);
                }
            }
            return temp;
        }

        public string ExecuteReceiving(ReceiptInfo receipt, List<ReceiptDetailInfo> receiptDetailInfoList)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < receiptDetailInfoList.Count; i++)
                {
                    temp = temp + this.ExecuteReceiving(dataBase, tran, receipt, receiptDetailInfoList[i], whLoginID) + ",";
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                this.receiptDetailInfoLists.Clear();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            SysSettingInfo sysSettinginfo = sysSettingDA.GetSysSettingByID("CEAWebService", whLoginID, this.pubParasInfo);
            if (((sysSettinginfo != null) && (sysSettinginfo.Value == "Y")) && (this.receiptDetailInfoLists.Count > 0))
            {
                ReceiptInfo receiptInfo = new ReceiptInfo();
                receiptInfo = receipt;
                foreach (ReceiptDetailInfo info in this.receiptDetailInfoLists)
                {
                    info.Udf3 = receiptInfo.Udf2;
                    info.Udf4 = receiptInfo.Udf3;
                }
                receiptInfo.Udf10 = new CEABLL(this.pubParasInfo).ReceivingPosting(this.receiptDetailInfoLists);
                if (!string.IsNullOrEmpty(receiptInfo.Udf10))
                {
                    receiptDA.UpdateReceipt(receiptInfo, whLoginID);
                }
            }
            return (string.IsNullOrEmpty(temp) ? "" : temp.Substring(0, temp.Length - 1));
        }

        public string ExecuteReceiving(ReceiptInfo receipt, ReceiptDetailInfo receiptDetailInfo)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            IntransitDetailBLL intransitDetailBll = new IntransitDetailBLL();
            IntransitBLL intransitBll = new IntransitBLL();
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                temp = this.ExecuteReceiving(dataBase, tran, receipt, receiptDetailInfo, whLoginID);
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                this.receiptDetailInfoLists.Clear();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            SysSettingInfo sysSettinginfo = sysSettingDA.GetSysSettingByID("CEAWebService", whLoginID, this.pubParasInfo);
            if (sysSettinginfo != null)
            {
                if (!(sysSettinginfo.Value == "Y"))
                {
                    return temp;
                }
                if (this.receiptDetailInfoLists.Count <= 0)
                {
                    return temp;
                }
                ReceiptInfo receiptInfo = new ReceiptInfo();
                receiptInfo = receipt;
                foreach (ReceiptDetailInfo info in this.receiptDetailInfoLists)
                {
                    info.Udf3 = receiptInfo.Udf2;
                    info.Udf4 = receiptInfo.Udf3;
                }
                receiptInfo.Udf10 = new CEABLL(this.pubParasInfo).ReceivingPosting(this.receiptDetailInfoLists);
                if (!string.IsNullOrEmpty(receiptInfo.Udf10))
                {
                    receiptDA.UpdateReceipt(receiptInfo, whLoginID);
                }
            }
            return temp;
        }

        public string ExecuteReceiving(DataBase dataBase, DbTransaction tran, ReceiptInfo receipt, ReceiptDetailInfo receiptDetailInfo, string whLoginID)
        {
            GenPutawayLocInfo genPutawayLocInfo;
            string temp = string.Empty;
            string transID = string.Empty;
            InboundHelper inboundHelper = new InboundHelper();
            IntransitDetailBLL intransitDetailBll = new IntransitDetailBLL();
            IntransitBLL intransitBll = new IntransitBLL();
            SysSettingInfo sysSettinginfo = sysSettingDA.GetSysSettingByID(dataBase, tran, "ReceivingCheckSAPValidation", whLoginID, this.pubParasInfo);
            if (((sysSettinginfo != null) && (sysSettinginfo.Value == "Y")) && (((receipt != null) && ((receipt.ReceiptType.ToUpper() == "NORMAL") || (receipt.ReceiptType.ToUpper() == "CROSSDOCK"))) && (receipt.SAPAuthentication.ToUpper() != "Y")))
            {
                PublicMethod.GetInstance().ShowAlertMessage("F4200_025", this.pubParasInfo.UserLanguage);
            }
            if (((receiptDetailInfo.Status == ReceiptStatus.ReceivedComplete) || (receiptDetailInfo.Status == ReceiptStatus.Cancelled)) || (receiptDetailInfo.Status == ReceiptStatus.Closed))
            {
                PublicMethod.GetInstance().ShowAlertMessage("F4200_013", this.pubParasInfo.UserLanguage);
            }
            if (!string.IsNullOrEmpty(receiptDetailInfo.ToLoc) && !locationDA.CheckLocationIDUnique(dataBase, tran, receiptDetailInfo.ToLoc, whLoginID))
            {
                PublicMethod.GetInstance().ShowAlertMessage("F4200_014", this.pubParasInfo.UserLanguage);
            }
            if (!packDA.CheckPackIDUnique(dataBase, tran, receiptDetailInfo.PackID, whLoginID))
            {
                PublicMethod.GetInstance().ShowAlertMessage("F4200_015", this.pubParasInfo.UserLanguage);
            }
            receiptDetailInfo.ReceiptLot.LotAttr10 = receiptDetailInfo.ReceiptID;
            string lotID = inboundHelper.CheckLotAttributeInfo(dataBase, tran, receiptDetailInfo.ReceiptLot, receiptDetailInfo.OwnerID, receiptDetailInfo.SkuID, whLoginID, this.pubParasInfo.UserID);
            receiptDetailInfo.ToLot = lotID;
            if (!string.IsNullOrEmpty(receiptDetailInfo.ToLoc))
            {
                inboundHelper.CheckLocationAttribute(dataBase, tran, receiptDetailInfo, whLoginID);
            }
            else
            {
                genPutawayLocInfo = new GenPutawayLocInfo(receiptDetailInfo.ReceiptID, receiptDetailInfo.ReceiptLineID.ToString(), receiptDetailInfo.OwnerID, receiptDetailInfo.SkuID, receiptDetailInfo.ToLot, receiptDetailInfo.ToLoc, receiptDetailInfo.ToLpnID, receiptDetailInfo.ReceivedQty);
                receiptDetailInfo.ToLoc = this.GetLocByPAStrategy(dataBase, tran, genPutawayLocInfo, whLoginID);
            }
            transID = inboundHelper.InsertInvTrans(dataBase, tran, receiptDetailInfo, TransType.Receipt, TransSourceType.ReceiptDetailAdd, TransStatus.OK, receiptDetailInfo.ReceiptID, receiptDetailInfo.ReceiptLineID, whLoginID);
            inboundHelper.UpdateInvSkuLocQty(dataBase, tran, receiptDetailInfo, "add", whLoginID);
            inboundHelper.UpdateInvLotQty(dataBase, tran, receiptDetailInfo, "add", whLoginID);
            inboundHelper.UpdateLpn(dataBase, tran, receiptDetailInfo, "add", whLoginID);
            inboundHelper.UpdateInvLotLocLpn(dataBase, tran, receiptDetailInfo, "add", whLoginID);
            inboundHelper.UpdateReceiptDetailQtyStatus(dataBase, tran, receipt, receiptDetailInfo, "add", whLoginID, this.pubParasInfo);
            receipt.ReceiptDate = receiptDetailInfo.ReceivedDate;
            inboundHelper.UpdateReceiptQtyStatus(dataBase, tran, receipt, whLoginID, this.pubParasInfo);
            if (!string.IsNullOrEmpty(receiptDetailInfo.PoID))
            {
                inboundHelper.UpdatePoQtyStatus(dataBase, tran, receiptDetailInfo, "add", whLoginID, this.pubParasInfo);
            }
            if ((receipt.ReceiptType == ReceiptTypes.Transfer) && !string.IsNullOrEmpty(receipt.ExternalReceiptId2))
            {
                string srcWhLoginID = commonMethod.GetDataBaseID(dataBase, tran, receipt.CreatedBy)[0];
                IntransitInfo intransitInfo = intransitBll.GetIntransitInfoByID(dataBase, tran, receipt.ExternalReceiptId2, receipt.CreatedBy);
                if ((intransitInfo != null) && !string.IsNullOrEmpty(intransitInfo.IntransitID))
                {
                    if ((intransitInfo.IntransitDetailInfos != null) && (intransitInfo.IntransitDetailInfos.Count > 0))
                    {
                        foreach (IntransitDetailInfo intransitDetailInfo in intransitInfo.IntransitDetailInfos)
                        {
                            if (intransitDetailInfo.OrderLineID == receiptDetailInfo.ReceiptLineID)
                            {
                                intransitDetailInfo.ReceivedQty += receiptDetailInfo.ReceivedQty;
                                string intransitDetailStatus = intransitDetailBll.GetIntransitDetailStatus(intransitDetailInfo);
                                inTransitDetailDA.UpdateIntransitDetailQty(dataBase, tran, intransitInfo.OrderID, receiptDetailInfo.ReceiptLineID.ToString(), IntransitUpdateType.ReceivedQty, receiptDetailInfo.ReceivedQty, intransitDetailStatus, receiptDetailInfo.UpdatedBy, srcWhLoginID);
                            }
                        }
                    }
                    string intransitStatus = intransitBll.GetIntransitInfoStatus(intransitInfo);
                    inTransitDA.UpdateIntransitStatus(dataBase, tran, intransitInfo.IntransitID, intransitStatus, receiptDetailInfo.UpdatedBy, srcWhLoginID);
                }
            }
            temp = receiptDetailInfo.ReceiptLineID.ToString();
            this.receiptDetailInfoLists.Add(receiptDetailInfo);
            SkuInfo skuInfo = skuDA.GetSkuByID(dataBase, tran, receiptDetailInfo.OwnerID, receiptDetailInfo.SkuID, whLoginID);
            if ((skuInfo != null) && (skuInfo.CalculatePutawayLocation.ToUpper() == "RECEIVING"))
            {
                InventoryMgtBLL inventoryMgtBll = new InventoryMgtBLL(this.pubParasInfo);
                this.RevertSkuLocExpectQtyAndDeletePendingPATask(dataBase, tran, inventoryMgtBll, transID, this.pubParasInfo.UserID, whLoginID);
                List<ReceiptPutawayInfo> receiptPutawayInfoList = null;
                if (string.IsNullOrEmpty(receiptDetailInfo.ToLpnID))
                {
                    receiptPutawayInfoList = this.PalletizingForReceiving(dataBase, tran, receiptDetailInfo, skuInfo, transID, whLoginID);
                }
                else
                {
                    receiptPutawayInfoList = new List<ReceiptPutawayInfo>();
                    ReceiptPutawayInfo tmp = new ReceiptPutawayInfo {
                        CaseID = receiptDetailInfo.CaseID,
                        CondititonCode = receiptDetailInfo.ConditionCode,
                        FromLoc = receiptDetailInfo.ToLoc,
                        FromLpnID = receiptDetailInfo.ToLpnID,
                        Lot = receiptDetailInfo.ToLot,
                        Lpn = receiptDetailInfo.ToLpnID,
                        OwnerID = receiptDetailInfo.OwnerID,
                        PackID = receiptDetailInfo.PackID,
                        Qty = receiptDetailInfo.ReceivedQty,
                        ReceiptID = receiptDetailInfo.ReceiptID,
                        ReceiptLineID = receiptDetailInfo.ReceiptLineID.ToString(),
                        SkuID = receiptDetailInfo.SkuID
                    };
                    genPutawayLocInfo = new GenPutawayLocInfo(tmp.ReceiptID, tmp.ReceiptLineID, tmp.OwnerID, tmp.SkuID, tmp.Lot, tmp.FromLoc, tmp.Lpn, tmp.Qty);
                    tmp.ToLoc = this.GetLocByPAStrategy(dataBase, tran, genPutawayLocInfo, whLoginID);
                    tmp.TransID = transID;
                    tmp.Uom = receiptDetailInfo.UomID;
                    tmp.UpdatedBy = receiptDetailInfo.UpdatedBy;
                    tmp.WhID = receiptDetailInfo.WhID;
                    receiptPutawayInfoList.Add(tmp);
                }
                if ((receiptPutawayInfoList != null) && (receiptPutawayInfoList.Count > 0))
                {
                    for (int i = 0; i < receiptPutawayInfoList.Count; i++)
                    {
                        this.GeneratePutAway(dataBase, tran, receiptPutawayInfoList[i], whLoginID);
                    }
                }
            }
            if (!string.IsNullOrEmpty(receiptDetailInfo.PoID))
            {
                this.ReceiveingUpdateXorderDetail(dataBase, tran, receiptDetailInfo, whLoginID);
            }
            return temp;
        }

        public string ExecuteReceivingAll(string receiptID)
        {
            Exception ex;
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            string updatedBy = this.pubParasInfo.UserID;
            try
            {
                ReceiptInfo receiptInfo = receiptDA.GetReceiptByID(receiptID, whLoginID, this.pubParasInfo);
                SysSettingInfo sysSettinginfo = sysSettingDA.GetSysSettingByID("ReceivingCheckSAPValidation", whLoginID, this.pubParasInfo);
                if (((sysSettinginfo != null) && (sysSettinginfo.Value == "Y")) && (((receiptInfo != null) && ((receiptInfo.ReceiptType.ToUpper() == "NORMAL") || (receiptInfo.ReceiptType.ToUpper() == "CROSSDOCK"))) && (receiptInfo.SAPAuthentication.ToUpper() != "Y")))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F4200_025", this.pubParasInfo.UserLanguage);
                }
                List<ReceiptDetailInfo> tempReceiptDetailInfos = null;
                string where = "(RD.STATUS = 'New' OR RD.STATUS = 'InReceiving') ";
                if (receiptInfo.IsPalletized == "Y")
                {
                    tempReceiptDetailInfos = receiptDetailLpnDA.GetReceiptDetailListByWhere(receiptID, where, whLoginID, this.pubParasInfo);
                }
                else
                {
                    tempReceiptDetailInfos = receiptDetailDA.GetReceiptDetailListByWhere(receiptID, where, whLoginID, this.pubParasInfo);
                }
                if ((tempReceiptDetailInfos != null) && (tempReceiptDetailInfos.Count > 0))
                {
                    int i;
                    InboundHelper inboundHelper = new InboundHelper();
                    List<List<ReceiptDetailInfo>> receiptDetailInfos = new List<List<ReceiptDetailInfo>>();
                    List<ReceiptDetailInfo> tempReceiptDetailInfo = new List<ReceiptDetailInfo>();
                    Dictionary<string, SkuInfo> skuInfoList = new Dictionary<string, SkuInfo>();
                    Dictionary<string, ReceiptValidationInfo> receiptValidationInfoList = new Dictionary<string, ReceiptValidationInfo>();
                    int reCounter = 0;
                    int counter = 0;
                    int faultCounter = 0;
                    for (i = 0; i < tempReceiptDetailInfos.Count; i++)
                    {
                        if (tempReceiptDetailInfos[i].Status != ReceiptStatus.ReceivedComplete)
                        {
                            SkuInfo skuInfo = null;
                            if (skuInfoList.ContainsKey(tempReceiptDetailInfos[i].OwnerID + tempReceiptDetailInfos[i].SkuID))
                            {
                                skuInfo = skuInfoList[tempReceiptDetailInfos[i].OwnerID + tempReceiptDetailInfos[i].SkuID];
                            }
                            else
                            {
                                skuInfo = skuDA.GetSkuByID(tempReceiptDetailInfos[i].OwnerID, tempReceiptDetailInfos[i].SkuID, whLoginID);
                                skuInfoList.Add(tempReceiptDetailInfos[i].OwnerID + tempReceiptDetailInfos[i].SkuID, skuInfo);
                            }
                            ReceiptValidationInfo receiptValidationInfo = null;
                            if (receiptValidationInfoList.ContainsKey(skuInfo.ReceiptValidationID))
                            {
                                receiptValidationInfo = receiptValidationInfoList[skuInfo.ReceiptValidationID];
                            }
                            else
                            {
                                receiptValidationInfo = receiptValidationDA.GetReceiptValidationByID(skuInfo.ReceiptValidationID, whLoginID);
                                receiptValidationInfoList.Add(skuInfo.ReceiptValidationID, receiptValidationInfo);
                            }
                            tempReceiptDetailInfos[i].ToLpnID = tempReceiptDetailInfos[i].LpnID;
                            this.ReceivingValidate(tempReceiptDetailInfos[i], receiptValidationInfo, whLoginID);
                            tempReceiptDetailInfos[i] = this.InitReceiptDetailInfo4Receiving(tempReceiptDetailInfos[i], inboundHelper, whLoginID);
                            if (skuInfo.ShelfLifeIndicator == "Y")
                            {
                                DateTime CS00002;
                                if (skuInfo.ShelfLifeCodeType.ToUpper() == "E")
                                {
                                    CS00002 = tempReceiptDetailInfos[i].ReceiptLot.ExpiryDate;
                                    if ((!string.IsNullOrEmpty(CS00002.ToString()) && (tempReceiptDetailInfos[i].ReceiptLot.ExpiryDate != new DateTime())) && (tempReceiptDetailInfos[i].ReceiptLot.ReceiptDate.AddDays((double) skuInfo.ShelfLifeOnReceiving) > tempReceiptDetailInfos[i].ReceiptLot.ExpiryDate))
                                    {
                                        throw new Exception("该行项" + tempReceiptDetailInfos[i].ReceiptLineID.ToString() + "入库保质期不满足!");
                                    }
                                }
                                else
                                {
                                    CS00002 = tempReceiptDetailInfos[i].ReceiptLot.ProduceDate;
                                    if ((!string.IsNullOrEmpty(CS00002.ToString()) && (tempReceiptDetailInfos[i].ReceiptLot.ProduceDate != new DateTime())) && (tempReceiptDetailInfos[i].ReceiptLot.ProduceDate.AddDays((double) skuInfo.ShelfLifeOnReceiving) > tempReceiptDetailInfos[i].ReceiptLot.ReceiptDate))
                                    {
                                        throw new Exception("该行项" + tempReceiptDetailInfos[i].ReceiptLineID.ToString() + "入库保质期不满足!");
                                    }
                                }
                            }
                            sysSettinginfo = sysSettingDA.GetSysSettingByID("RDMustBeLargerThanPD", whLoginID, this.pubParasInfo);
                            if (((sysSettinginfo != null) && (sysSettinginfo.Value == "Y")) && (tempReceiptDetailInfos[i].ReceiptLot.ProduceDate > tempReceiptDetailInfos[i].ReceiptLot.ReceiptDate))
                            {
                                throw new Exception("该行项" + tempReceiptDetailInfos[i].ReceiptLineID.ToString() + "入库日期必须大于生产日期!");
                            }
                            string toLoc = "Stage";
                            if (!string.IsNullOrEmpty(tempReceiptDetailInfos[i].ToLoc))
                            {
                                toLoc = tempReceiptDetailInfos[i].ToLoc;
                            }
                            else if (skuInfo != null)
                            {
                                ZoneInfo zoneInfo = zoneDA.GetZoneByID(skuInfo.ZoneID, whLoginID);
                                if (zoneInfo != null)
                                {
                                    toLoc = string.IsNullOrEmpty(zoneInfo.InLoc) ? "Stage" : zoneInfo.InLoc;
                                }
                            }
                            tempReceiptDetailInfos[i].ToLoc = toLoc;
                            tempReceiptDetailInfo.Add(tempReceiptDetailInfos[i]);
                            counter++;
                        }
                        else
                        {
                            faultCounter++;
                        }
                        if (counter == 100)
                        {
                            receiptDetailInfos.Add(tempReceiptDetailInfo);
                            tempReceiptDetailInfo = new List<ReceiptDetailInfo>();
                            counter = 0;
                            reCounter++;
                        }
                        else if (((reCounter * 100) + counter) == (tempReceiptDetailInfos.Count - faultCounter))
                        {
                            receiptDetailInfos.Add(tempReceiptDetailInfo);
                        }
                    }
                    for (i = 0; i < receiptDetailInfos.Count; i++)
                    {
                        try
                        {
                            this.ExecuteReceiving(receiptInfo, receiptDetailInfos[i]);
                        }
                        catch (Exception exception1)
                        {
                            ex = exception1;
                            temp = temp + ((i * 10)).ToString() + ex.Message + ",";
                        }
                    }
                }
            }
            catch (Exception exception2)
            {
                ex = exception2;
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            if (!string.IsNullOrEmpty(temp))
            {
                return temp.Substring(0, temp.Length - 1);
            }
            return temp;
        }

        public string ExecuteScanReceiving(List<ReceiptDetailInfo> receiptDetailList)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            ReceiptInfo receipt = receiptDA.GetReceiptByID(receiptDetailList[0].ReceiptID, whLoginID, this.pubParasInfo);
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                foreach (ReceiptDetailInfo info in receiptDetailList)
                {
                    if (!(string.IsNullOrEmpty(info.ReceiptID) || string.IsNullOrEmpty(info.SkuID)))
                    {
                        this.ExecuteReceiving(dataBase, tran, receipt, info, whLoginID);
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                this.receiptDetailInfoLists.Clear();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            SysSettingInfo sysSettinginfo = sysSettingDA.GetSysSettingByID("CEAWebService", whLoginID, this.pubParasInfo);
            if (sysSettinginfo != null)
            {
                if (!(sysSettinginfo.Value == "Y"))
                {
                    return temp;
                }
                if (this.receiptDetailInfoLists.Count <= 0)
                {
                    return temp;
                }
                ReceiptInfo receiptInfo = receiptDA.GetReceiptByID(this.receiptDetailInfoLists[0].ReceiptID, whLoginID, this.pubParasInfo);
                foreach (ReceiptDetailInfo info in this.receiptDetailInfoLists)
                {
                    info.Udf3 = receiptInfo.Udf2;
                    info.Udf4 = receiptInfo.Udf3;
                }
                receiptInfo.Udf10 = new CEABLL(this.pubParasInfo).ReceivingPosting(this.receiptDetailInfoLists);
                if (!string.IsNullOrEmpty(receiptInfo.Udf10))
                {
                    receiptDA.UpdateReceipt(receiptInfo, whLoginID);
                }
            }
            return temp;
        }

        public string GeneratePutAway(List<ReceiptPutawayInfo> receiptPutawayInfo)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                int i;
                InboundHelper inboundHelper = new InboundHelper();
                InventoryMgtBLL inventoryMgtBll = new InventoryMgtBLL();
                ReceiptDetailInfo receiptDetailInfo = receiptDetailDA.GetReceiptDetailByID(dataBase, tran, receiptPutawayInfo[0].ReceiptID, receiptPutawayInfo[0].ReceiptLineID, whLoginID, this.pubParasInfo);
                for (i = 0; i < receiptPutawayInfo.Count; i++)
                {
                    this.RevertSkuLocExpectQtyAndDeletePendingPATask(dataBase, tran, inventoryMgtBll, receiptPutawayInfo[i].TransID, this.pubParasInfo.UserID, whLoginID);
                }
                PackInfo packInfo = packDA.GetPackByID(dataBase, tran, receiptDetailInfo.PackID, whLoginID);
                for (i = 0; i < receiptPutawayInfo.Count; i++)
                {
                    receiptPutawayInfo[i].WhID = receiptDetailInfo.WhID;
                    receiptPutawayInfo[i].CaseID = receiptDetailInfo.CaseID;
                    receiptPutawayInfo[i].FromLpnID = receiptPutawayInfo[i].Lpn;
                    receiptPutawayInfo[i].UpdatedBy = this.pubParasInfo.UserID;
                    receiptDetailInfo.ReceivedQty = inboundHelper.ExchangeUom(packInfo, receiptPutawayInfo[i].Uom, receiptPutawayInfo[i].Qty, "W");
                    receiptPutawayInfo[i].Qty = receiptDetailInfo.ReceivedQty;
                    receiptDetailInfo.UomID = packInfo.PackUom1;
                    receiptPutawayInfo[i].Uom = packInfo.PackUom1;
                    receiptDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                    inventoryMgtBll.UpdateInvSkuLocExceptedQty(dataBase, tran, receiptPutawayInfo[i].OwnerID, receiptPutawayInfo[i].SkuID, receiptPutawayInfo[i].ToLoc, receiptPutawayInfo[i].Qty, this.pubParasInfo.UserID, whLoginID);
                    inventoryMgtBll.UpdateInvLotLocLpnPendingQty(dataBase, tran, receiptPutawayInfo[i].Lot, receiptPutawayInfo[i].FromLoc, receiptPutawayInfo[i].Lpn, receiptPutawayInfo[i].Qty, this.pubParasInfo.UserID, whLoginID);
                    inboundHelper.InsertPutawayTaskDetail(dataBase, tran, receiptPutawayInfo[i], TaskType.PA, TaskPriority.nine, whLoginID);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return temp;
        }

        public string GeneratePutAway(DataBase dataBase, DbTransaction tran, ReceiptPutawayInfo receiptPutawayInfo, string whLoginID)
        {
            InboundHelper inboundHelper = new InboundHelper();
            InventoryMgtBLL inventoryMgtBll = new InventoryMgtBLL();
            PackInfo packInfo = packDA.GetPackByID(dataBase, tran, receiptPutawayInfo.PackID, whLoginID);
            receiptPutawayInfo.Uom = packInfo.PackUom1;
            inventoryMgtBll.UpdateInvSkuLocExceptedQty(dataBase, tran, receiptPutawayInfo.OwnerID, receiptPutawayInfo.SkuID, receiptPutawayInfo.ToLoc, receiptPutawayInfo.Qty, this.pubParasInfo.UserID, whLoginID);
            inventoryMgtBll.UpdateInvLotLocLpnPendingQty(dataBase, tran, receiptPutawayInfo.Lot, receiptPutawayInfo.FromLoc, receiptPutawayInfo.FromLpnID, receiptPutawayInfo.Qty, this.pubParasInfo.UserID, whLoginID);
            return inboundHelper.InsertPutawayTaskDetail(dataBase, tran, receiptPutawayInfo, TaskType.PA, TaskPriority.nine, whLoginID);
        }

        public string GeneratePutAwayByReceiptHistory(ReceiptHistoryInfo receiptHistoryInfo, InventoryMgtBLL inventoryMgtBll, string updatedBy, string whLoginID)
        {
            string tmp = string.Empty;
            if (receiptHistoryInfo.Status != TaskStatus.Completed)
            {
                DataBase dataBase = new DataBase();
                DbConnection conn = dataBase.connection;
                conn.Open();
                DbTransaction tran = conn.BeginTransaction();
                try
                {
                    receiptHistoryInfo.ReceivedQty = receiptHistoryInfo.RemainQty;
                    this.RevertSkuLocExpectQtyAndDeletePendingPATask(dataBase, tran, inventoryMgtBll, receiptHistoryInfo.TransID, updatedBy, whLoginID);
                    GenPutawayLocInfo genPutawayLocInfo = new GenPutawayLocInfo(receiptHistoryInfo.ReceiptID, receiptHistoryInfo.ReceiptLineID, receiptHistoryInfo.OwnerID, receiptHistoryInfo.SkuID, receiptHistoryInfo.LotID, receiptHistoryInfo.Loc, receiptHistoryInfo.Lpn, receiptHistoryInfo.ReceivedQty);
                    string putAwayLoc = this.GetLocByPAStrategy(dataBase, tran, genPutawayLocInfo, whLoginID);
                    ReceiptPutawayInfo receiptPutawayInfo = new ReceiptPutawayInfo {
                        CondititonCode = receiptHistoryInfo.CondititonCode,
                        FromLpnID = receiptHistoryInfo.Lpn,
                        Lpn = receiptHistoryInfo.Lpn,
                        OwnerID = receiptHistoryInfo.OwnerID,
                        FromLoc = receiptHistoryInfo.Loc,
                        PackID = receiptHistoryInfo.PackID,
                        Qty = receiptHistoryInfo.ReceivedQty,
                        ReceiptID = receiptHistoryInfo.ReceiptID,
                        ReceiptLineID = receiptHistoryInfo.ReceiptLineID,
                        SkuID = receiptHistoryInfo.SkuID,
                        ToLoc = putAwayLoc,
                        TransID = receiptHistoryInfo.TransID,
                        Uom = receiptHistoryInfo.Uom,
                        Lot = receiptHistoryInfo.LotID,
                        UpdatedBy = updatedBy,
                        WhID = whLoginID.Substring(0, whLoginID.Length - 1)
                    };
                    tmp = this.GeneratePutAway(dataBase, tran, receiptPutawayInfo, whLoginID);
                    tran.Commit();
                }
                catch (Exception)
                {
                    tran.Rollback();
                }
                finally
                {
                    conn.Close();
                }
            }
            return tmp;
        }

        public DataSet GetAllReceiptDetail()
        {
            return receiptDetailDA.GetAllReceiptDetail(this.dataBaseID[0], this.pubParasInfo);
        }

        private string GetAsn2LotAttrField(string asnRefer, ReceiptDetailInfo receiptDetailInfo)
        {
            string result = string.Empty;
            string CS40001 = asnRefer.ToUpper();
            if (CS40001 == null)
            {
                return result;
            }
            if (!(CS40001 == "RECEIPT_LINE_ID"))
            {
                if (CS40001 != "EXTERN_RECEIPT_ID")
                {
                    if (CS40001 == "EXTERN_LINE_ID")
                    {
                        return receiptDetailInfo.ExternLineID.ToString();
                    }
                    if (CS40001 == "PO_ID")
                    {
                        return receiptDetailInfo.PoID.ToString();
                    }
                    if (CS40001 != "PO_LINE_ID")
                    {
                        return result;
                    }
                    return receiptDetailInfo.PoLineID.ToString();
                }
            }
            else
            {
                return receiptDetailInfo.ReceiptLineID.ToString();
            }
            return receiptDetailInfo.ExternReceiptID.ToString();
        }

        public string GetLocByPAStrategy(DataBase dataBase, DbTransaction tran, GenPutawayLocInfo genPutawayLocInfo, string whLoginID)
        {
            string putAwayLoc = string.Empty;
            SkuInfo skuInfo = skuDA.GetSkuByID(dataBase, tran, genPutawayLocInfo.OwnerID, genPutawayLocInfo.SkuID, whLoginID);
            List<PutawayRuleDetailInfo> putAwayRuleDetailInfo = putawayRuleDetailDA.GetPutawayRuleDetailListByID(dataBase, tran, skuInfo.PutawayRuleID, whLoginID, this.pubParasInfo);
            if ((putAwayRuleDetailInfo != null) && (putAwayRuleDetailInfo.Count > 0))
            {
                for (int i = 0; i < putAwayRuleDetailInfo.Count; i++)
                {
                    if (putAwayRuleDetailInfo[i].IsActive == "Y")
                    {
                        List<string> putAwayLocs = new List<string>();
                        string tempPutAwayLoc = string.Empty;
                        DataSet putawayLocDs = null;
                        switch (putAwayRuleDetailInfo[i].PaStrategy)
                        {
                            case "10":
                                putawayLocDs = receiptDetailDA.GetPutAwayLocByPaStrategy(dataBase, tran, "10", "", genPutawayLocInfo.OwnerID, genPutawayLocInfo.SkuID, whLoginID);
                                break;

                            case "20":
                                putawayLocDs = receiptDetailDA.GetPutAwayLocByPaStrategy(dataBase, tran, "20", "", genPutawayLocInfo.OwnerID, genPutawayLocInfo.SkuID, whLoginID);
                                break;

                            case "30":
                                putawayLocDs = receiptDetailDA.GetPutAwayLocByPaStrategy(dataBase, tran, "30", putAwayRuleDetailInfo[i].Zone, "", "", whLoginID);
                                break;

                            case "40":
                                tempPutAwayLoc = putAwayRuleDetailInfo[i].ToLoc;
                                putAwayLocs.Add(tempPutAwayLoc);
                                break;

                            case "50":
                                if (genPutawayLocInfo.Loc.ToUpper() == putAwayRuleDetailInfo[i].FromLoc.ToUpper())
                                {
                                    tempPutAwayLoc = putAwayRuleDetailInfo[i].ToLoc;
                                    putAwayLocs.Add(tempPutAwayLoc);
                                }
                                break;

                            case "60":
                                if (genPutawayLocInfo.Loc.ToUpper() == putAwayRuleDetailInfo[i].FromLoc.ToUpper())
                                {
                                    putawayLocDs = receiptDetailDA.GetPutAwayLocByPaStrategy(dataBase, tran, "60", putAwayRuleDetailInfo[i].Zone, "", "", whLoginID);
                                }
                                break;

                            case "70":
                                putawayLocDs = receiptDetailDA.GetPutAwayLocByPaStrategy(dataBase, tran, "70", "", genPutawayLocInfo.OwnerID, genPutawayLocInfo.SkuID, whLoginID);
                                break;

                            case "80":
                                putawayLocDs = receiptDetailDA.GetPutAwayLocByPaStrategy(dataBase, tran, "80", "", genPutawayLocInfo.OwnerID, genPutawayLocInfo.SkuID, whLoginID);
                                break;
                        }
                        if ((putawayLocDs != null) && (putawayLocDs.Tables[0].Rows.Count > 0))
                        {
                            for (int j = 0; j < putawayLocDs.Tables[0].Rows.Count; j++)
                            {
                                putAwayLocs.Add(putawayLocDs.Tables[0].Rows[j][0].ToString());
                            }
                        }
                        if ((putAwayLocs != null) && (putAwayLocs.Count > 0))
                        {
                            for (int k = 0; k < putAwayLocs.Count; k++)
                            {
                                if (!string.IsNullOrEmpty(putAwayRuleDetailInfo[i].LocSelection))
                                {
                                    if ((this.CheckLocByLocFilter(dataBase, tran, putAwayLocs[k], putAwayRuleDetailInfo[i].LocSelection, genPutawayLocInfo, whLoginID) && this.CheckLocStatusLimitByPAStrategy(dataBase, tran, putAwayLocs[k], putAwayRuleDetailInfo[i], genPutawayLocInfo, whLoginID)) && this.CheckDimRestrictionByPAStratety(dataBase, tran, putAwayLocs[k], skuInfo, genPutawayLocInfo, putAwayRuleDetailInfo[i], whLoginID))
                                    {
                                        putAwayLoc = putAwayLocs[k];
                                        break;
                                    }
                                }
                                else if (this.CheckLocStatusLimitByPAStrategy(dataBase, tran, putAwayLocs[k], putAwayRuleDetailInfo[i], genPutawayLocInfo, whLoginID) && this.CheckDimRestrictionByPAStratety(dataBase, tran, putAwayLocs[k], skuInfo, genPutawayLocInfo, putAwayRuleDetailInfo[i], whLoginID))
                                {
                                    putAwayLoc = putAwayLocs[k];
                                    break;
                                }
                            }
                        }
                        if (!string.IsNullOrEmpty(putAwayLoc))
                        {
                            break;
                        }
                    }
                }
            }
            if (string.IsNullOrEmpty(putAwayLoc))
            {
                putAwayLoc = "UNKNOWN";
            }
            return putAwayLoc;
        }

        public ReceiptDetailInfo GetNextUncompletedReceiptDetailInfo(string receiptID)
        {
            return receiptDetailDA.GetNextUncompletedReceiptDetailInfo(receiptID, this.dataBaseID[0], this.pubParasInfo);
        }

        public List<ReceiptPutawayInfo> GetPendingPutAwayTaskByTransID(string transID)
        {
            List<ReceiptPutawayInfo> receiptPutawayInfos = receiptDetailDA.GetPendingPutAwayTaskByTransID(transID, this.dataBaseID[0]);
            if ((receiptPutawayInfos != null) && (receiptPutawayInfos.Count > 0))
            {
                PackInfo packInfo = packDA.GetPackByID(receiptPutawayInfos[0].PackID, this.dataBaseID[0]);
                InboundHelper inboundHelper = new InboundHelper();
                for (int i = 0; i < receiptPutawayInfos.Count; i++)
                {
                    receiptPutawayInfos[i].Qty = inboundHelper.ExchangeUom(packInfo, receiptPutawayInfos[i].Uom, receiptPutawayInfos[i].Qty, "R");
                }
            }
            return receiptPutawayInfos;
        }

        public DataSet GetPutAwayDetailByPagerQueryEntity(PutawayDetailQueryEntity putawayDetailQueryEntity)
        {
            List<string> strWhere = new List<string>();
            return receiptDetailDA.GetPutAwayDetailByPagerQueryList(strWhere, putawayDetailQueryEntity, this.dataBaseID[0], this.pubParasInfo);
        }

        public ReceiptDetailInfo GetReceiptDetailInfoByID(string receiptID, string receiptLineID)
        {
            ReceiptDetailInfo receiptDetailInfo = receiptDetailDA.GetReceiptDetailByID(receiptID, receiptLineID, this.dataBaseID[0], this.pubParasInfo);
            if (receiptDetailInfo != null)
            {
                receiptDetailInfo.HadReceivedQty = receiptDetailDA.GetReceivedQtyByReceiptDetailID(receiptID, receiptLineID, this.dataBaseID[0]);
                InboundHelper inboundHelper = new InboundHelper();
                PackInfo packInfo = packDA.GetPackByID(receiptDetailInfo.PackID, this.dataBaseID[0]);
                receiptDetailInfo.ExpectedQty = inboundHelper.ExchangeUom(packInfo, receiptDetailInfo.UomID, receiptDetailInfo.ExpectedQty, "R");
                receiptDetailInfo.ReceivedQty = inboundHelper.ExchangeUom(packInfo, receiptDetailInfo.UomID, receiptDetailInfo.ReceivedQty, "R");
                receiptDetailInfo.HadReceivedQty = inboundHelper.ExchangeUom(packInfo, receiptDetailInfo.UomID, receiptDetailInfo.HadReceivedQty, "R");
            }
            return receiptDetailInfo;
        }

        public DataSet GetReceiptDetailInfoByPagerQueryEntity(ReceiptDetailQueryEntity receiptDetailQueryEntity)
        {
            List<string> strWhere = new List<string>();
            if (!string.IsNullOrEmpty(receiptDetailQueryEntity.SkuID))
            {
                strWhere.Add(" RD.SKU_ID " + receiptDetailQueryEntity.SkuID);
            }
            if (!string.IsNullOrEmpty(receiptDetailQueryEntity.Status))
            {
                strWhere.Add(" RD.STATUS " + receiptDetailQueryEntity.Status);
            }
            DataSet ds = null;
            if (receiptDetailQueryEntity.IsPalletized == "Y")
            {
                ds = receiptDetailLpnDA.GetReceiptDetailByPagerQueryList(strWhere, receiptDetailQueryEntity, this.dataBaseID[0], this.pubParasInfo);
            }
            else
            {
                ds = receiptDetailDA.GetReceiptDetailByPagerQueryList(strWhere, receiptDetailQueryEntity, this.dataBaseID[0], this.pubParasInfo);
            }
            if ((ds != null) && (ds.Tables.Count > 2))
            {
                if ((ds.Tables[2] == null) || (ds.Tables[2].Rows.Count <= 0))
                {
                    return ds;
                }
                InboundHelper inboundHelper = new InboundHelper();
                Dictionary<string, PackInfo> packInfoList = new Dictionary<string, PackInfo> { };
                if (receiptDetailQueryEntity.IsPalletized == "Y")
                {
                    ds.Tables[1].Rows[0]["LineID"] = commonMethod.GetMaxLineID("RECEIPT_DETAIL_LPN", receiptDetailQueryEntity.ReceiptID, this.dataBaseID[0]);
                }
                else
                {
                    ds.Tables[1].Rows[0]["LineID"] = commonMethod.GetMaxLineID("RECEIPT_DETAIL", receiptDetailQueryEntity.ReceiptID, this.dataBaseID[0]);
                }
                for (int i = 0; i < ds.Tables[2].Rows.Count; i++)
                {
                    if (!string.IsNullOrEmpty(ds.Tables[1].Rows[0]["TotalExpectedQty"].ToString()))
                    {
                        ds.Tables[1].Rows[0]["TotalExpectedQty"] = Convert.ToDecimal(ds.Tables[1].Rows[0]["TotalExpectedQty"]) + Convert.ToDecimal(ds.Tables[2].Rows[i]["EXPECTED_QTY"]);
                    }
                    else
                    {
                        ds.Tables[1].Rows[0]["TotalExpectedQty"] = ds.Tables[2].Rows[i]["EXPECTED_QTY"].ToString();
                    }
                    if (!string.IsNullOrEmpty(ds.Tables[1].Rows[0]["TotalReceivedQty"].ToString()))
                    {
                        ds.Tables[1].Rows[0]["TotalReceivedQty"] = Convert.ToDecimal(ds.Tables[1].Rows[0]["TotalReceivedQty"]) + Convert.ToDecimal(ds.Tables[2].Rows[i]["RECEIVED_QTY"]);
                    }
                    else
                    {
                        ds.Tables[1].Rows[0]["TotalReceivedQty"] = ds.Tables[2].Rows[i]["RECEIVED_QTY"].ToString();
                    }
                    if (!string.IsNullOrEmpty(ds.Tables[1].Rows[0]["TotalGrossWgt"].ToString()))
                    {
                        ds.Tables[1].Rows[0]["TotalGrossWgt"] = Convert.ToDecimal(ds.Tables[1].Rows[0]["TotalGrossWgt"]) + Convert.ToDecimal(ds.Tables[2].Rows[i]["GROSS_WGT"]);
                    }
                    else
                    {
                        ds.Tables[1].Rows[0]["TotalGrossWgt"] = ds.Tables[2].Rows[i]["GROSS_WGT"].ToString();
                    }
                    if (!string.IsNullOrEmpty(ds.Tables[1].Rows[0]["TotalCube"].ToString()))
                    {
                        ds.Tables[1].Rows[0]["TotalCube"] = Convert.ToDecimal(ds.Tables[1].Rows[0]["TotalCube"]) + Convert.ToDecimal(ds.Tables[2].Rows[i]["Cube"]);
                    }
                    else
                    {
                        ds.Tables[1].Rows[0]["TotalCube"] = ds.Tables[2].Rows[i]["Cube"].ToString();
                    }
                    PackInfo packInfo = null;
                    if (packInfoList.ContainsKey(ds.Tables[2].Rows[i]["PACK_ID"].ToString()))
                    {
                        packInfo = packInfoList[ds.Tables[2].Rows[i]["PACK_ID"].ToString()];
                    }
                    else
                    {
                        packInfo = packDA.GetPackByID(ds.Tables[2].Rows[i]["PACK_ID"].ToString(), this.dataBaseID[0]);
                        packInfoList.Add(ds.Tables[2].Rows[i]["PACK_ID"].ToString(), packInfo);
                    }
                    ds.Tables[2].Rows[i]["RECEIVED_QTY"] = inboundHelper.ExchangeUom(packInfo, ds.Tables[2].Rows[i]["UOM_ID"].ToString(), Convert.ToDecimal(ds.Tables[2].Rows[i]["RECEIVED_QTY"]), "R");
                    ds.Tables[2].Rows[i]["EXPECTED_QTY"] = inboundHelper.ExchangeUom(packInfo, ds.Tables[2].Rows[i]["UOM_ID"].ToString(), Convert.ToDecimal(ds.Tables[2].Rows[i]["EXPECTED_QTY"]), "R");
                }
            }
            return ds;
        }

        public DataSet GetReceiptDetailInfoByQueryEntity(ReceiptDetailQueryEntity receiptQueryEntity)
        {
            ReceiptDetailQueryEntity receiptQuery = receiptQueryEntity;
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(receiptQuery.ReceiptID))
            {
                sqlWhere.Add(" RD.RECEIPT_ID " + receiptQuery.ReceiptID);
            }
            if (!string.IsNullOrEmpty(receiptQuery.ReceiptType))
            {
                sqlWhere.Add(" RD.RECEIPT_TYPE " + receiptQuery.ReceiptType);
            }
            if (!string.IsNullOrEmpty(receiptQuery.OwnerID))
            {
                sqlWhere.Add(" RD.OWNER_ID " + receiptQuery.OwnerID);
            }
            if (!string.IsNullOrEmpty(receiptQuery.ExternalReceiptID))
            {
                sqlWhere.Add(" RD.EXTERNAL_RECEIPT_ID " + receiptQuery.ExternalReceiptID);
            }
            if (!string.IsNullOrEmpty(receiptQuery.ExpectedReceiptDate))
            {
                sqlWhere.Add(" RD.EXPECTED_RECEIPT_DATE " + receiptQuery.ExpectedReceiptDate);
            }
            if (!string.IsNullOrEmpty(receiptQuery.LottableMatchRequired))
            {
                sqlWhere.Add(" RD.LOTTABLE_MATCH_REQUIRED " + receiptQuery.LottableMatchRequired);
            }
            if (!string.IsNullOrEmpty(receiptQuery.IsActive))
            {
                sqlWhere.Add(" RD.IS_ACTIVE " + receiptQuery.IsActive);
            }
            if (!string.IsNullOrEmpty(receiptQuery.Status))
            {
                sqlWhere.Add("  RD.STATUS" + receiptQuery.Status);
            }
            return receiptDetailDA.GetReceiptDetailByQueryList(sqlWhere, receiptQuery, this.dataBaseID[0], this.pubParasInfo);
        }

        public List<ReceiptDetailInfo> GetReceiptDetailInfoListByID(string receiptID)
        {
            return receiptDetailDA.GetReceiptDetailListByID(receiptID, this.dataBaseID[0], this.pubParasInfo);
        }

        public DataSet GetReceiptInquiryInfoByQueryEntity(ReceiptDetailQueryEntity receiptQueryEntity)
        {
            ReceiptDetailQueryEntity receiptQuery = receiptQueryEntity;
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(receiptQuery.ReceiptID))
            {
                sqlWhere.Add(" R.RECEIPT_ID " + receiptQuery.ReceiptID);
            }
            if (!string.IsNullOrEmpty(receiptQuery.PoID))
            {
                sqlWhere.Add(" R.PO_ID " + receiptQuery.PoID);
            }
            if (!string.IsNullOrEmpty(receiptQuery.ReceiptType))
            {
                sqlWhere.Add(" R.RECEIPT_TYPE " + receiptQuery.ReceiptType);
            }
            if (!string.IsNullOrEmpty(receiptQuery.OwnerID))
            {
                sqlWhere.Add(" R.OWNER_ID " + receiptQuery.OwnerID);
            }
            if (!string.IsNullOrEmpty(receiptQuery.ExternalReceiptID))
            {
                sqlWhere.Add(" R.EXTERNAL_RECEIPT_ID " + receiptQuery.ExternalReceiptID);
            }
            if (!string.IsNullOrEmpty(receiptQuery.ExpectedReceiptDate))
            {
                sqlWhere.Add(receiptQuery.ExpectedReceiptDate.Replace("@ExpectedReceiptData@", " R.EXPECTED_RECEIPT_DATE "));
            }
            if (!string.IsNullOrEmpty(receiptQuery.ReceiptDate))
            {
                sqlWhere.Add(receiptQuery.ReceiptDate.Replace("@ReceiptDate@", " R.RECEIPT_DATE "));
            }
            if (!string.IsNullOrEmpty(receiptQuery.LottableMatchRequired))
            {
                sqlWhere.Add(" R.LOTTABLE_MATCH_REQUIRED " + receiptQuery.LottableMatchRequired);
            }
            if (!string.IsNullOrEmpty(receiptQuery.IsActive))
            {
                sqlWhere.Add(" R.IS_ACTIVE " + receiptQuery.IsActive);
            }
            if (!string.IsNullOrEmpty(receiptQuery.Status))
            {
                sqlWhere.Add("  R.STATUS " + receiptQuery.Status);
            }
            if (!string.IsNullOrEmpty(receiptQuery.SkuID))
            {
                sqlWhere.Add("  R.SKU_ID " + receiptQuery.SkuID);
            }
            if (!string.IsNullOrEmpty(receiptQuery.SkuClassID))
            {
                sqlWhere.Add("  R.SKU_CLASS_ID " + receiptQuery.SkuClassID);
            }
            if (!string.IsNullOrEmpty(receiptQuery.VendorID))
            {
                sqlWhere.Add("  R.VENDOR_ID " + receiptQuery.VendorID);
            }
            if (!string.IsNullOrEmpty(receiptQuery.ExternalLot))
            {
                sqlWhere.Add("  R.EXTERNAL_LOT " + receiptQuery.ExternalLot);
            }
            return receiptDetailDA.GetReceiptInquiryInfoByQueryEntity(sqlWhere, receiptQuery, this.dataBaseID[0], this.pubParasInfo);
        }

        public List<string> GetUnPrintPutawayTaskIDByReceiptID(string receiptID)
        {
            List<string> taskDetailIDs = new List<string>();
            DataSet ds = receiptDetailDA.GetUnPrintPutawayTaskIDByReceiptID(receiptID, this.dataBaseID[0]);
            if (((ds != null) && (ds.Tables.Count > 0)) && (ds.Tables[0].Rows.Count > 0))
            {
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    taskDetailIDs.Add(row["TASK_DETAIL_ID"].ToString());
                }
            }
            return taskDetailIDs;
        }

        public ReceiptDetailInfo InitReceiptDetailInfo4Receiving(ReceiptDetailInfo receiptDetailInfo, InboundHelper inboundHelper, string whLoginID)
        {
            string result;
            TradePartnerInfo ownerInfo = tradePartnerDA.GetTradePartnerByID(receiptDetailInfo.OwnerID, whLoginID, this.pubParasInfo);
            if ((ownerInfo.IsAsnreferToLot01 == "Y") && (!string.IsNullOrEmpty(ownerInfo.AsnRefer01) && !string.IsNullOrEmpty(ownerInfo.AsnToLotAttr01)))
            {
                result = this.GetAsn2LotAttrField(ownerInfo.AsnRefer01, receiptDetailInfo);
                switch (ownerInfo.AsnToLotAttr01.ToUpper())
                {
                    case "LOT_ATTR01":
                        receiptDetailInfo.ReceiptLot.LotAttr01 = result;
                        break;

                    case "LOT_ATTR02":
                        receiptDetailInfo.ReceiptLot.LotAttr02 = result;
                        break;

                    case "LOT_ATTR03":
                        receiptDetailInfo.ReceiptLot.LotAttr03 = result;
                        break;

                    case "LOT_ATTR04":
                        receiptDetailInfo.ReceiptLot.LotAttr04 = result;
                        break;

                    case "LOT_ATTR05":
                        receiptDetailInfo.ReceiptLot.LotAttr05 = result;
                        break;

                    case "LOT_ATTR06":
                        receiptDetailInfo.ReceiptLot.LotAttr06 = result;
                        break;

                    case "LOT_ATTR07":
                        receiptDetailInfo.ReceiptLot.LotAttr07 = result;
                        break;

                    case "LOT_ATTR08":
                        receiptDetailInfo.ReceiptLot.LotAttr08 = result;
                        break;
                }
            }
            if ((ownerInfo.IsAsnreferToLot02 == "Y") && (!string.IsNullOrEmpty(ownerInfo.AsnRefer02) && !string.IsNullOrEmpty(ownerInfo.AsnToLotAttr02)))
            {
                result = this.GetAsn2LotAttrField(ownerInfo.AsnRefer02, receiptDetailInfo);
                switch (ownerInfo.AsnToLotAttr02.ToUpper())
                {
                    case "LOT_ATTR01":
                        receiptDetailInfo.ReceiptLot.LotAttr01 = result;
                        break;

                    case "LOT_ATTR02":
                        receiptDetailInfo.ReceiptLot.LotAttr02 = result;
                        break;

                    case "LOT_ATTR03":
                        receiptDetailInfo.ReceiptLot.LotAttr03 = result;
                        break;

                    case "LOT_ATTR04":
                        receiptDetailInfo.ReceiptLot.LotAttr04 = result;
                        break;

                    case "LOT_ATTR05":
                        receiptDetailInfo.ReceiptLot.LotAttr05 = result;
                        break;

                    case "LOT_ATTR06":
                        receiptDetailInfo.ReceiptLot.LotAttr06 = result;
                        break;

                    case "LOT_ATTR07":
                        receiptDetailInfo.ReceiptLot.LotAttr07 = result;
                        break;

                    case "LOT_ATTR08":
                        receiptDetailInfo.ReceiptLot.LotAttr08 = result;
                        break;
                }
            }
            if ((ownerInfo.IsAsnreferToLot03 == "Y") && (!string.IsNullOrEmpty(ownerInfo.AsnRefer03) && !string.IsNullOrEmpty(ownerInfo.AsnToLotAttr03)))
            {
                result = this.GetAsn2LotAttrField(ownerInfo.AsnRefer03, receiptDetailInfo);
                switch (ownerInfo.AsnToLotAttr03.ToUpper())
                {
                    case "LOT_ATTR01":
                        receiptDetailInfo.ReceiptLot.LotAttr01 = result;
                        break;

                    case "LOT_ATTR02":
                        receiptDetailInfo.ReceiptLot.LotAttr02 = result;
                        break;

                    case "LOT_ATTR03":
                        receiptDetailInfo.ReceiptLot.LotAttr03 = result;
                        break;

                    case "LOT_ATTR04":
                        receiptDetailInfo.ReceiptLot.LotAttr04 = result;
                        break;

                    case "LOT_ATTR05":
                        receiptDetailInfo.ReceiptLot.LotAttr05 = result;
                        break;

                    case "LOT_ATTR06":
                        receiptDetailInfo.ReceiptLot.LotAttr06 = result;
                        break;

                    case "LOT_ATTR07":
                        receiptDetailInfo.ReceiptLot.LotAttr07 = result;
                        break;

                    case "LOT_ATTR08":
                        receiptDetailInfo.ReceiptLot.LotAttr08 = result;
                        break;
                }
            }
            if ((ownerInfo.IsAsnreferToLot04 == "Y") && (!string.IsNullOrEmpty(ownerInfo.AsnRefer04) && !string.IsNullOrEmpty(ownerInfo.AsnToLotAttr04)))
            {
                result = this.GetAsn2LotAttrField(ownerInfo.AsnRefer04, receiptDetailInfo);
                switch (ownerInfo.AsnToLotAttr04.ToUpper())
                {
                    case "LOT_ATTR01":
                        receiptDetailInfo.ReceiptLot.LotAttr01 = result;
                        break;

                    case "LOT_ATTR02":
                        receiptDetailInfo.ReceiptLot.LotAttr02 = result;
                        break;

                    case "LOT_ATTR03":
                        receiptDetailInfo.ReceiptLot.LotAttr03 = result;
                        break;

                    case "LOT_ATTR04":
                        receiptDetailInfo.ReceiptLot.LotAttr04 = result;
                        break;

                    case "LOT_ATTR05":
                        receiptDetailInfo.ReceiptLot.LotAttr05 = result;
                        break;

                    case "LOT_ATTR06":
                        receiptDetailInfo.ReceiptLot.LotAttr06 = result;
                        break;

                    case "LOT_ATTR07":
                        receiptDetailInfo.ReceiptLot.LotAttr07 = result;
                        break;

                    case "LOT_ATTR08":
                        receiptDetailInfo.ReceiptLot.LotAttr08 = result;
                        break;
                }
            }
            if ((ownerInfo.IsAsnreferToLot05 == "Y") && (!string.IsNullOrEmpty(ownerInfo.AsnRefer05) && !string.IsNullOrEmpty(ownerInfo.AsnToLotAttr05)))
            {
                result = this.GetAsn2LotAttrField(ownerInfo.AsnRefer05, receiptDetailInfo);
                switch (ownerInfo.AsnToLotAttr05.ToUpper())
                {
                    case "LOT_ATTR01":
                        receiptDetailInfo.ReceiptLot.LotAttr01 = result;
                        break;

                    case "LOT_ATTR02":
                        receiptDetailInfo.ReceiptLot.LotAttr02 = result;
                        break;

                    case "LOT_ATTR03":
                        receiptDetailInfo.ReceiptLot.LotAttr03 = result;
                        break;

                    case "LOT_ATTR04":
                        receiptDetailInfo.ReceiptLot.LotAttr04 = result;
                        break;

                    case "LOT_ATTR05":
                        receiptDetailInfo.ReceiptLot.LotAttr05 = result;
                        break;

                    case "LOT_ATTR06":
                        receiptDetailInfo.ReceiptLot.LotAttr06 = result;
                        break;

                    case "LOT_ATTR07":
                        receiptDetailInfo.ReceiptLot.LotAttr07 = result;
                        break;

                    case "LOT_ATTR08":
                        receiptDetailInfo.ReceiptLot.LotAttr08 = result;
                        break;
                }
            }
            if (!this.CheckMandatoryLotAttribute(receiptDetailInfo, whLoginID))
            {
                throw new Exception("订单行" + receiptDetailInfo.ReceiptLineID.ToString() + " 请输入批次属性信息!");
            }
            receiptDetailInfo.FromLoc = "";
            receiptDetailInfo.FromLpnID = "";
            if (string.IsNullOrEmpty(receiptDetailInfo.ToLoc))
            {
                receiptDetailInfo.ToLoc = ConstUtils.CONST_DETAIL_RECEIVING_LOC;
            }
            receiptDetailInfo.ToLpnID = receiptDetailInfo.LpnID;
            PackInfo packInfo = packDA.GetPackByID(receiptDetailInfo.PackID, whLoginID);
            receiptDetailInfo.ReceivedQty = receiptDetailInfo.ExpectedQty - receiptDetailInfo.ReceivedQty;
            receiptDetailInfo.ReceivedQty = inboundHelper.ExchangeUom(packInfo, receiptDetailInfo.UomID, receiptDetailInfo.ReceivedQty, "R");
            DateTime CS00004 = new DateTime();
            if (receiptDetailInfo.ReceiptLot.ReceiptDate == CS00004)
            {
                receiptDetailInfo.ReceiptLot.ReceiptDate = DateTime.Now;
            }
            if (receiptDetailInfo.ReceivedDate == new DateTime())
            {
                receiptDetailInfo.ReceivedDate = receiptDetailInfo.ReceiptLot.ReceiptDate;
            }
            receiptDetailInfo.ConditionCode = string.IsNullOrEmpty(receiptDetailInfo.ConditionCode) ? "OK" : receiptDetailInfo.ConditionCode;
            receiptDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
            return receiptDetailInfo;
        }

        public string InsertReceiptDetail(ReceiptDetailInfo receiptDetailInfo)
        {
            string whLoginID = this.dataBaseID[0];
            string lineID = string.Empty;
            try
            {
                if (receiptDetailInfo == null)
                {
                    return lineID;
                }
                if (receiptDetailDA.CheckReceiptDetailIDUnique(receiptDetailInfo.ReceiptID, receiptDetailInfo.ReceiptLineID.ToString(), this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F4200_010", this.pubParasInfo.UserLanguage, new List<string> { receiptDetailInfo.ReceiptID, receiptDetailInfo.ReceiptLineID.ToString() });
                }
                if (!string.IsNullOrEmpty(receiptDetailInfo.VendorID))
                {
                    IVendorDA vendorDA = DataAccess.CreateVendorDA();
                    if (!vendorDA.CheckVendorIDUnique(receiptDetailInfo.VendorID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F4200_006", this.pubParasInfo.UserLanguage, new List<string> { receiptDetailInfo.VendorID });
                    }
                    else if (!vendorDA.CheckAuthorizationVendorIDUserID(receiptDetailInfo.VendorID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2130_002", this.pubParasInfo.UserLanguage, new List<string> { receiptDetailInfo.VendorID });
                    }
                }
                if (!skuDA.CheckSkuIDUnique(receiptDetailInfo.OwnerID, receiptDetailInfo.SkuID, this.dataBaseID[0]))
                {
                    PublicMethod.GetInstance().ShowAlertMessage("F4200_011", this.pubParasInfo.UserLanguage, new List<string> { receiptDetailInfo.SkuID });
                }
                receiptDetailInfo.ExpectedQty = new InboundHelper().ExchangeUom(receiptDetailInfo.PackID, receiptDetailInfo.UomID, receiptDetailInfo.ExpectedQty, "W", whLoginID);
                receiptDetailInfo.UpdatedBy = receiptDetailInfo.CreatedBy;
                receiptDetailInfo.CreatedDate = DateTime.Now;
                receiptDetailInfo.UpdatedDate = DateTime.Now;
                if (receiptDetailInfo.IsPalletized == "N")
                {
                    if (receiptDetailDA.InsertReceiptDetail(receiptDetailInfo, whLoginID) > 0)
                    {
                        AuditDataBLL auditDataBLL = new AuditDataBLL();
                        auditDataBLL.InsertAuditData<ReceiptDetailInfo>(null, receiptDetailInfo, AuditAction.Insert, this.pubParasInfo.UserID, "RECEIPT_DETAIL", this.dataBaseID[0]);
                        lineID = receiptDetailInfo.ReceiptLineID.ToString();
                    }
                    return lineID;
                }
                if (string.IsNullOrEmpty(receiptDetailInfo.LpnID))
                {
                    receiptDetailInfo.LpnID = commonMethod.GenNextNumStr("LPN", this.dataBaseID[0]);
                }
                if (receiptDetailLpnDA.InsertReceiptDetailLpn(receiptDetailInfo, whLoginID) > 0)
                {
                    new AuditDataBLL().InsertAuditData<ReceiptDetailInfo>(null, receiptDetailInfo, AuditAction.Insert, this.pubParasInfo.UserID, "RECEIPT_DETAIL_LPN", this.dataBaseID[0]);
                    lineID = receiptDetailInfo.ReceiptLineID.ToString();
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return lineID;
        }

        public List<ReceiptPutawayInfo> PalletizingForReceiving(DataBase dataBase, DbTransaction tran, ReceiptDetailInfo receiptDetailInfo, SkuInfo skuInfo, string transID, string whLoginID)
        {
            int factor;
            int i;
            ReceiptPutawayInfo tmp;
            GenPutawayLocInfo genPutawayLocInfo;
            List<ReceiptPutawayInfo> receiptPutawayInfoList = new List<ReceiptPutawayInfo>();
            decimal remainQty = receiptDetailInfo.ReceivedQty;
            PackInfo packInfo = packDA.GetPackByID(dataBase, tran, skuInfo.PackID, whLoginID);
            if ((packInfo.IsInLabelUom4 == "Y") && ((packInfo.Pallet > 0f) && (Convert.ToDecimal(packInfo.Pallet) <= remainQty)))
            {
                factor = Convert.ToInt32(Math.Floor((decimal) (remainQty / Convert.ToDecimal(packInfo.Pallet))));
                for (i = 0; i < factor; i++)
                {
                    tmp = new ReceiptPutawayInfo {
                        CaseID = receiptDetailInfo.CaseID,
                        CondititonCode = receiptDetailInfo.ConditionCode,
                        FromLoc = receiptDetailInfo.ToLoc,
                        FromLpnID = receiptDetailInfo.FromLpnID,
                        Lot = receiptDetailInfo.ToLot,
                        Lpn = commonMethod.GenNextNumStr(dataBase, tran, "LPN", whLoginID),
                        OwnerID = receiptDetailInfo.OwnerID,
                        PackID = receiptDetailInfo.PackID,
                        Qty = Convert.ToDecimal(packInfo.Pallet),
                        ReceiptID = receiptDetailInfo.ReceiptID,
                        ReceiptLineID = receiptDetailInfo.ReceiptLineID.ToString(),
                        SkuID = receiptDetailInfo.SkuID
                    };
                    genPutawayLocInfo = new GenPutawayLocInfo(tmp.ReceiptID, tmp.ReceiptLineID, tmp.OwnerID, tmp.SkuID, tmp.Lot, tmp.FromLoc, tmp.Lpn, tmp.Qty);
                    tmp.ToLoc = this.GetLocByPAStrategy(dataBase, tran, genPutawayLocInfo, whLoginID);
                    tmp.TransID = transID;
                    tmp.Uom = receiptDetailInfo.UomID;
                    tmp.UpdatedBy = receiptDetailInfo.UpdatedBy;
                    tmp.WhID = receiptDetailInfo.WhID;
                    receiptPutawayInfoList.Add(tmp);
                    remainQty -= Convert.ToDecimal(packInfo.Pallet);
                }
            }
            if ((packInfo.IsInLabelUom3 == "Y") && ((packInfo.CaseCnt > 0f) && (Convert.ToDecimal(packInfo.CaseCnt) <= remainQty)))
            {
                factor = Convert.ToInt32(Math.Floor((decimal) (remainQty / Convert.ToDecimal(packInfo.CaseCnt))));
                for (i = 0; i < factor; i++)
                {
                    tmp = new ReceiptPutawayInfo {
                        CaseID = receiptDetailInfo.CaseID,
                        CondititonCode = receiptDetailInfo.ConditionCode,
                        FromLoc = receiptDetailInfo.ToLoc,
                        FromLpnID = receiptDetailInfo.FromLpnID,
                        Lot = receiptDetailInfo.ToLot,
                        Lpn = commonMethod.GenNextNumStr(dataBase, tran, "LPN", whLoginID),
                        OwnerID = receiptDetailInfo.OwnerID,
                        PackID = receiptDetailInfo.PackID,
                        Qty = Convert.ToDecimal(packInfo.CaseCnt),
                        ReceiptID = receiptDetailInfo.ReceiptID,
                        ReceiptLineID = receiptDetailInfo.ReceiptLineID.ToString(),
                        SkuID = receiptDetailInfo.SkuID
                    };
                    genPutawayLocInfo = new GenPutawayLocInfo(tmp.ReceiptID, tmp.ReceiptLineID, tmp.OwnerID, tmp.SkuID, tmp.Lot, tmp.FromLoc, tmp.Lpn, tmp.Qty);
                    tmp.ToLoc = this.GetLocByPAStrategy(dataBase, tran, genPutawayLocInfo, whLoginID);
                    tmp.TransID = transID;
                    tmp.Uom = receiptDetailInfo.UomID;
                    tmp.UpdatedBy = receiptDetailInfo.UpdatedBy;
                    tmp.WhID = receiptDetailInfo.WhID;
                    receiptPutawayInfoList.Add(tmp);
                    remainQty -= Convert.ToDecimal(packInfo.CaseCnt);
                }
            }
            if ((packInfo.IsInLabelUom2 == "Y") && ((packInfo.InnerPack > 0f) && (Convert.ToDecimal(packInfo.InnerPack) <= remainQty)))
            {
                factor = Convert.ToInt32(Math.Floor((decimal) (remainQty / Convert.ToDecimal(packInfo.InnerPack))));
                for (i = 0; i < factor; i++)
                {
                    tmp = new ReceiptPutawayInfo {
                        CaseID = receiptDetailInfo.CaseID,
                        CondititonCode = receiptDetailInfo.ConditionCode,
                        FromLoc = receiptDetailInfo.ToLoc,
                        FromLpnID = receiptDetailInfo.FromLpnID,
                        Lot = receiptDetailInfo.ToLot,
                        Lpn = commonMethod.GenNextNumStr(dataBase, tran, "LPN", whLoginID),
                        OwnerID = receiptDetailInfo.OwnerID,
                        PackID = receiptDetailInfo.PackID,
                        Qty = Convert.ToDecimal(packInfo.InnerPack),
                        ReceiptID = receiptDetailInfo.ReceiptID,
                        ReceiptLineID = receiptDetailInfo.ReceiptLineID.ToString(),
                        SkuID = receiptDetailInfo.SkuID
                    };
                    genPutawayLocInfo = new GenPutawayLocInfo(tmp.ReceiptID, tmp.ReceiptLineID, tmp.OwnerID, tmp.SkuID, tmp.Lot, tmp.FromLoc, tmp.Lpn, tmp.Qty);
                    tmp.ToLoc = this.GetLocByPAStrategy(dataBase, tran, genPutawayLocInfo, whLoginID);
                    tmp.TransID = transID;
                    tmp.Uom = receiptDetailInfo.UomID;
                    tmp.UpdatedBy = receiptDetailInfo.UpdatedBy;
                    tmp.WhID = receiptDetailInfo.WhID;
                    receiptPutawayInfoList.Add(tmp);
                    remainQty -= Convert.ToDecimal(packInfo.InnerPack);
                }
            }
            if ((packInfo.IsInLabelUom1 == "Y") && ((packInfo.Qty > 0f) && (Convert.ToDecimal(packInfo.Qty) <= remainQty)))
            {
                factor = Convert.ToInt32(Math.Floor((decimal) (remainQty / Convert.ToDecimal(packInfo.Qty))));
                for (i = 0; i < factor; i++)
                {
                    tmp = new ReceiptPutawayInfo {
                        CaseID = receiptDetailInfo.CaseID,
                        CondititonCode = receiptDetailInfo.ConditionCode,
                        FromLoc = receiptDetailInfo.ToLoc,
                        FromLpnID = receiptDetailInfo.FromLpnID,
                        Lot = receiptDetailInfo.ToLot,
                        Lpn = commonMethod.GenNextNumStr(dataBase, tran, "LPN", whLoginID),
                        OwnerID = receiptDetailInfo.OwnerID,
                        PackID = receiptDetailInfo.PackID,
                        Qty = Convert.ToDecimal(packInfo.Qty),
                        ReceiptID = receiptDetailInfo.ReceiptID,
                        ReceiptLineID = receiptDetailInfo.ReceiptLineID.ToString(),
                        SkuID = receiptDetailInfo.SkuID
                    };
                    genPutawayLocInfo = new GenPutawayLocInfo(tmp.ReceiptID, tmp.ReceiptLineID, tmp.OwnerID, tmp.SkuID, tmp.Lot, tmp.FromLoc, tmp.Lpn, tmp.Qty);
                    tmp.ToLoc = this.GetLocByPAStrategy(dataBase, tran, genPutawayLocInfo, whLoginID);
                    tmp.TransID = transID;
                    tmp.Uom = receiptDetailInfo.UomID;
                    tmp.UpdatedBy = receiptDetailInfo.UpdatedBy;
                    tmp.WhID = receiptDetailInfo.WhID;
                    receiptPutawayInfoList.Add(tmp);
                    remainQty -= Convert.ToDecimal(packInfo.Qty);
                }
            }
            if (remainQty > 0M)
            {
                tmp = new ReceiptPutawayInfo {
                    CaseID = receiptDetailInfo.CaseID,
                    CondititonCode = receiptDetailInfo.ConditionCode,
                    FromLoc = receiptDetailInfo.ToLoc,
                    FromLpnID = receiptDetailInfo.FromLpnID,
                    Lot = receiptDetailInfo.ToLot,
                    Lpn = commonMethod.GenNextNumStr(dataBase, tran, "LPN", whLoginID),
                    OwnerID = receiptDetailInfo.OwnerID,
                    PackID = receiptDetailInfo.PackID,
                    Qty = Convert.ToDecimal(remainQty),
                    ReceiptID = receiptDetailInfo.ReceiptID,
                    ReceiptLineID = receiptDetailInfo.ReceiptLineID.ToString(),
                    SkuID = receiptDetailInfo.SkuID
                };
                genPutawayLocInfo = new GenPutawayLocInfo(tmp.ReceiptID, tmp.ReceiptLineID, tmp.OwnerID, tmp.SkuID, tmp.Lot, tmp.FromLoc, tmp.Lpn, tmp.Qty);
                tmp.ToLoc = this.GetLocByPAStrategy(dataBase, tran, genPutawayLocInfo, whLoginID);
                tmp.TransID = transID;
                tmp.Uom = receiptDetailInfo.UomID;
                tmp.UpdatedBy = receiptDetailInfo.UpdatedBy;
                tmp.WhID = receiptDetailInfo.WhID;
                receiptPutawayInfoList.Add(tmp);
                remainQty -= Convert.ToDecimal(remainQty);
            }
            return receiptPutawayInfoList;
        }

        public string ReceiptDetailPriceChanges(string receiptID, string lineID, string IsPalletized, float price, float totalPrice)
        {
            string strtemp = string.Empty;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                if (IsPalletized == "Y")
                {
                    receiptDetailLpnDA.ReceiptDetailLpnPriceChanges(dataBase, tran, receiptID, lineID, (double) price, (double) totalPrice, this.dataBaseID[0], this.pubParasInfo.UserID);
                }
                else
                {
                    receiptDetailDA.ReceiptDetailPriceChanges(dataBase, tran, receiptID, lineID, (double) price, (double) totalPrice, this.dataBaseID[0], this.pubParasInfo.UserID);
                }
                List<InvTransInfo> invtransinfo = invTransDA.GetInvTransListByReceiptID(dataBase, tran, receiptID, lineID, this.dataBaseID[0], this.pubParasInfo);
                if ((invtransinfo != null) && (invtransinfo.Count > 0))
                {
                    foreach (InvTransInfo Invinfo in invtransinfo)
                    {
                        invTransDA.UpdateInvTransUnitPriceByLot(dataBase, tran, Invinfo.Lot, price, this.dataBaseID[0], this.pubParasInfo.UserID);
                        invLotDA.UpdateInvLotUnitPriceBylot(dataBase, tran, Invinfo.Lot, price, this.pubParasInfo.UserID, this.dataBaseID[0]);
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return strtemp;
        }

        private void ReceiveingUpdateXorderDetail(DataBase database, DbTransaction tran, ReceiptDetailInfo receiptDetailInfo, string whLoginID)
        {
            PurchaseOrderInfo purchaseOrderInfo = purchaseOrderDA.GetPurchaseOrderByID(database, tran, receiptDetailInfo.PoID, whLoginID, this.pubParasInfo);
            if (((purchaseOrderInfo != null) && !string.IsNullOrEmpty(purchaseOrderInfo.PoID)) && (purchaseOrderInfo.PoType.ToUpper() == "FLOWTHRU"))
            {
                XordersInfo xordersInfo = xordersDA.GetXordersBypoID(database, tran, receiptDetailInfo.PoID, whLoginID);
                if (xordersInfo == null)
                {
                    throw new Exception("入库单" + receiptDetailInfo.ReceiptID + " 采购订单" + receiptDetailInfo.PoID + "为流转类型,请先创建直通分配订单,后在继续收货!");
                }
                List<XorderDetailInfo> xorderDetailInfo = xorderDetailDA.GetXorderDetailListByID(database, tran, xordersInfo.OrderID, whLoginID);
                if ((xorderDetailInfo != null) && (xorderDetailInfo.Count > 0))
                {
                    foreach (XorderDetailInfo info in xorderDetailInfo)
                    {
                        if ((info.SkuID == receiptDetailInfo.SkuID) && (info.OwnerID == receiptDetailInfo.OwnerID))
                        {
                            if ((info.OriginalQty - info.OpenQty) >= receiptDetailInfo.ReceivedQty)
                            {
                                info.OpenQty += receiptDetailInfo.ReceivedQty;
                            }
                            else
                            {
                                info.OpenQty += info.OriginalQty - info.OpenQty;
                            }
                            info.UpdatedBy = this.pubParasInfo.UserID;
                            xorderDetailDA.UpdateXorderDetail(database, tran, info, whLoginID);
                        }
                    }
                }
            }
        }

        private void ReceivingValidate(ReceiptDetailInfo receiptDetailInfo, string whLoginID)
        {
            SkuInfo skuInfo = skuDA.GetSkuByID(receiptDetailInfo.OwnerID, receiptDetailInfo.SkuID, whLoginID);
            if (skuInfo.ShelfLifeIndicator == "Y")
            {
                DateTime CS00001;
                if (skuInfo.ShelfLifeCodeType.ToUpper() == "E")
                {
                    CS00001 = receiptDetailInfo.ReceiptLot.ExpiryDate;
                    if ((!string.IsNullOrEmpty(CS00001.ToString()) && (receiptDetailInfo.ReceiptLot.ExpiryDate != new DateTime())) && (receiptDetailInfo.ReceiptLot.ReceiptDate.AddDays((double) skuInfo.ShelfLifeOnReceiving) > receiptDetailInfo.ReceiptLot.ExpiryDate))
                    {
                        throw new Exception("该行项" + receiptDetailInfo.ReceiptLineID.ToString() + "入库保质期不满足!");
                    }
                }
                else
                {
                    CS00001 = receiptDetailInfo.ReceiptLot.ProduceDate;
                    if ((!string.IsNullOrEmpty(CS00001.ToString()) && (receiptDetailInfo.ReceiptLot.ProduceDate != new DateTime())) && (receiptDetailInfo.ReceiptLot.ProduceDate.AddDays((double) skuInfo.ShelfLifeOnReceiving) > receiptDetailInfo.ReceiptLot.ReceiptDate))
                    {
                        throw new Exception("该行项" + receiptDetailInfo.ReceiptLineID.ToString() + "入库保质期不满足!");
                    }
                }
            }
            SysSettingInfo sysSettinginfo = sysSettingDA.GetSysSettingByID("RDMustBeLargerThanPD", whLoginID, this.pubParasInfo);
            if (((sysSettinginfo != null) && (sysSettinginfo.Value == "Y")) && (receiptDetailInfo.ReceiptLot.ProduceDate > receiptDetailInfo.ReceiptLot.ReceiptDate))
            {
                throw new Exception("该行项" + receiptDetailInfo.ReceiptLineID.ToString() + "入库日期必须大于生产日期!");
            }
            if (!string.IsNullOrEmpty(skuInfo.ReceiptValidationID))
            {
                ReceiptValidationInfo receiptValidationInfo = receiptValidationDA.GetReceiptValidationByID(skuInfo.ReceiptValidationID, whLoginID);
                if ((receiptValidationInfo != null) && (receiptValidationInfo.IsActive == "Y"))
                {
                    if (receiptValidationInfo.IsQtyValidation == "Y")
                    {
                        decimal receivedQty = receiptDetailDA.GetReceivedQtyByReceiptDetailID(receiptDetailInfo.ReceiptID, receiptDetailInfo.ReceiptLineID.ToString(), whLoginID);
                        if (receiptDetailInfo.ExpectedQty < (receiptDetailInfo.ReceivedQty + receivedQty))
                        {
                            decimal allowOverReceivedQty = Math.Ceiling((decimal) (receiptDetailInfo.ExpectedQty * (receiptValidationInfo.OveragePercent / 100M)));
                            if ((receiptDetailInfo.ExpectedQty + allowOverReceivedQty) < (receiptDetailInfo.ReceivedQty + receivedQty))
                            {
                                throw new Exception("该行项" + receiptDetailInfo.ReceiptLineID.ToString() + "已经超收,并超出超收范围,超收数量为: " + Convert.ToString((decimal) ((receiptDetailInfo.ReceivedQty + receivedQty) - (receiptDetailInfo.ExpectedQty + allowOverReceivedQty))));
                            }
                        }
                    }
                    if ((receiptValidationInfo.ReceiptWithoutLpn.ToUpper() != "ALLOW") && string.IsNullOrEmpty(receiptDetailInfo.ToLpnID))
                    {
                        throw new Exception("该行项" + receiptDetailInfo.ReceiptLineID.ToString() + "没有LPN,不允许接收!");
                    }
                }
            }
        }

        private void ReceivingValidate(ReceiptDetailInfo receiptDetailInfo, ReceiptValidationInfo receiptValidationInfo, string whLoginID)
        {
            if ((receiptValidationInfo != null) && (receiptValidationInfo.IsActive == "Y"))
            {
                if (receiptValidationInfo.IsQtyValidation == "Y")
                {
                    decimal receivedQty = receiptDetailDA.GetReceivedQtyByReceiptDetailID(receiptDetailInfo.ReceiptID, receiptDetailInfo.ReceiptLineID.ToString(), whLoginID);
                    if (receiptDetailInfo.ExpectedQty < (receiptDetailInfo.ReceivedQty + receivedQty))
                    {
                        decimal allowOverReceivedQty = Math.Ceiling((decimal) (receiptDetailInfo.ExpectedQty * (receiptValidationInfo.OveragePercent / 100M)));
                        if ((receiptDetailInfo.ExpectedQty + allowOverReceivedQty) < (receiptDetailInfo.ReceivedQty + receivedQty))
                        {
                            throw new Exception("该行项" + receiptDetailInfo.ReceiptLineID.ToString() + "已经超收,并超出超收范围,超收数量为: " + Convert.ToString((decimal) ((receiptDetailInfo.ReceivedQty + receivedQty) - (receiptDetailInfo.ExpectedQty + allowOverReceivedQty))));
                        }
                    }
                }
                if ((receiptValidationInfo.ReceiptWithoutLpn.ToUpper() != "ALLOW") && string.IsNullOrEmpty(receiptDetailInfo.ToLpnID))
                {
                    throw new Exception("该行项" + receiptDetailInfo.ReceiptLineID.ToString() + "没有LPN,不允许接收!");
                }
            }
        }

        private void ReceivingValidate(ReceiptDetailInfo receiptDetailInfo, SkuInfo skuInfo, string whLoginID)
        {
            if (skuInfo.ShelfLifeIndicator == "Y")
            {
                DateTime CS00001;
                if (skuInfo.ShelfLifeCodeType.ToUpper() == "E")
                {
                    CS00001 = receiptDetailInfo.ReceiptLot.ExpiryDate;
                    if ((!string.IsNullOrEmpty(CS00001.ToString()) && (receiptDetailInfo.ReceiptLot.ExpiryDate != new DateTime())) && (receiptDetailInfo.ReceiptLot.ReceiptDate.AddDays((double) skuInfo.ShelfLifeOnReceiving) > receiptDetailInfo.ReceiptLot.ExpiryDate))
                    {
                        throw new Exception("该行项" + receiptDetailInfo.ReceiptLineID.ToString() + "入库保质期不满足!");
                    }
                }
                else
                {
                    CS00001 = receiptDetailInfo.ReceiptLot.ProduceDate;
                    if ((!string.IsNullOrEmpty(CS00001.ToString()) && (receiptDetailInfo.ReceiptLot.ProduceDate != new DateTime())) && (receiptDetailInfo.ReceiptLot.ProduceDate.AddDays((double) skuInfo.ShelfLifeOnReceiving) > receiptDetailInfo.ReceiptLot.ReceiptDate))
                    {
                        throw new Exception("该行项" + receiptDetailInfo.ReceiptLineID.ToString() + "入库保质期不满足!");
                    }
                }
            }
            SysSettingInfo sysSettinginfo = sysSettingDA.GetSysSettingByID("RDMustBeLargerThanPD", whLoginID, this.pubParasInfo);
            if (((sysSettinginfo != null) && (sysSettinginfo.Value == "Y")) && (receiptDetailInfo.ReceiptLot.ProduceDate > receiptDetailInfo.ReceiptLot.ReceiptDate))
            {
                throw new Exception("该行项" + receiptDetailInfo.ReceiptLineID.ToString() + "入库日期必须大于生产日期!");
            }
            if (!string.IsNullOrEmpty(skuInfo.ReceiptValidationID))
            {
                ReceiptValidationInfo receiptValidationInfo = receiptValidationDA.GetReceiptValidationByID(skuInfo.ReceiptValidationID, whLoginID);
                if ((receiptValidationInfo != null) && (receiptValidationInfo.IsActive == "Y"))
                {
                    if (receiptValidationInfo.IsQtyValidation == "Y")
                    {
                        decimal receivedQty = receiptDetailDA.GetReceivedQtyByReceiptDetailID(receiptDetailInfo.ReceiptID, receiptDetailInfo.ReceiptLineID.ToString(), whLoginID);
                        if (receiptDetailInfo.ExpectedQty < (receiptDetailInfo.ReceivedQty + receivedQty))
                        {
                            decimal allowOverReceivedQty = Math.Ceiling((decimal) (receiptDetailInfo.ExpectedQty * (receiptValidationInfo.OveragePercent / 100M)));
                            if ((receiptDetailInfo.ExpectedQty + allowOverReceivedQty) < (receiptDetailInfo.ReceivedQty + receivedQty))
                            {
                                throw new Exception("该行项" + receiptDetailInfo.ReceiptLineID.ToString() + "已经超收,并超出超收范围,超收数量为: " + Convert.ToString((decimal) ((receiptDetailInfo.ReceivedQty + receivedQty) - (receiptDetailInfo.ExpectedQty + allowOverReceivedQty))));
                            }
                        }
                    }
                    if ((receiptValidationInfo.ReceiptWithoutLpn.ToUpper() != "ALLOW") && string.IsNullOrEmpty(receiptDetailInfo.ToLpnID))
                    {
                        throw new Exception("该行项" + receiptDetailInfo.ReceiptLineID.ToString() + "没有LPN,不允许接收!");
                    }
                }
            }
        }

        public void RevertSkuLocExpectQtyAndDeletePendingPATask(DataBase dataBase, DbTransaction tran, InventoryMgtBLL inventoryMgtBll, string transID, string updatedBy, string whLoginID)
        {
            List<TaskDetailInfo> taskDetailInfos = taskDetailDA.GetTaskDetailByFromTransID(dataBase, tran, transID, whLoginID, this.pubParasInfo);
            if ((taskDetailInfos != null) && (taskDetailInfos.Count > 0))
            {
                foreach (TaskDetailInfo taskDetailInfo in taskDetailInfos)
                {
                    inventoryMgtBll.UpdateInvSkuLocExceptedQty(dataBase, tran, taskDetailInfo.OwnerID, taskDetailInfo.SkuID, taskDetailInfo.ToLoc, taskDetailInfo.Qty * -1M, updatedBy, whLoginID);
                    inventoryMgtBll.UpdateInvLotLocLpnPendingQty(dataBase, tran, taskDetailInfo.Lot, taskDetailInfo.FromLoc, taskDetailInfo.FromLpnID, taskDetailInfo.Qty * -1M, updatedBy, whLoginID);
                }
                receiptDetailDA.DeletePutawayTaskDetail(dataBase, tran, transID, whLoginID);
            }
        }

        private bool SwitchDimRestriction(DataBase dataBase, DbTransaction tran, string suggestLoc, SkuInfo skuInfo, GenPutawayLocInfo genPutawayLocInfo, string dimRestriction, string whLoginID)
        {
            bool temp = true;
            if (string.IsNullOrEmpty(dimRestriction))
            {
                return temp;
            }
            if (dimRestriction == "10")
            {
                return true;
            }
            object obj = receiptDetailDA.CheckDimRestrictionByPAStratety(dataBase, tran, suggestLoc, dimRestriction, whLoginID);
            string CS40002 = dimRestriction;
            if (CS40002 == null)
            {
                return temp;
            }
            if (!(CS40002 == "20"))
            {
                decimal availableQty;
                if (CS40002 == "30")
                {
                    if ((obj == null) || string.IsNullOrEmpty(obj.ToString()))
                    {
                        return true;
                    }
                    if (decimal.Parse(obj.ToString()) >= 0M)
                    {
                        if (skuInfo.GrossWgt > 0f)
                        {
                            return ((decimal.Parse(obj.ToString()) - (decimal.Parse(skuInfo.GrossWgt.ToString()) * genPutawayLocInfo.Qty)) >= 0M);
                        }
                        return true;
                    }
                    return false;
                }
                if (CS40002 == "40")
                {
                    if ((obj == null) || string.IsNullOrEmpty(obj.ToString()))
                    {
                        return true;
                    }
                    if (decimal.Parse(obj.ToString()) > 0M)
                    {
                        if (skuInfo.Cube > 0f)
                        {
                            availableQty = decimal.Parse(obj.ToString()) / decimal.Parse(skuInfo.Cube.ToString());
                            return ((availableQty - genPutawayLocInfo.Qty) >= 0M);
                        }
                        return true;
                    }
                    return false;
                }
                if (CS40002 == "50")
                {
                    if ((obj == null) || string.IsNullOrEmpty(obj.ToString()))
                    {
                        return true;
                    }
                    if (decimal.Parse(obj.ToString()) >= 0M)
                    {
                        if (skuInfo.Cube > 0f)
                        {
                            availableQty = decimal.Parse(obj.ToString()) / decimal.Parse(skuInfo.Cube.ToString());
                            return ((availableQty - genPutawayLocInfo.Qty) >= 0M);
                        }
                        return true;
                    }
                    return false;
                }
                if (CS40002 != "60")
                {
                    return temp;
                }
                if ((obj != null) && !string.IsNullOrEmpty(obj.ToString()))
                {
                    if (decimal.Parse(obj.ToString()) >= 0M)
                    {
                        decimal skuCube = decimal.Parse(skuInfo.Cube.ToString()) * genPutawayLocInfo.Qty;
                        return ((decimal.Parse(obj.ToString()) - skuCube) >= 0M);
                    }
                    return false;
                }
                return true;
            }
            if ((obj == null) || string.IsNullOrEmpty(obj.ToString()))
            {
                return true;
            }
            if (decimal.Parse(obj.ToString()) >= 0M)
            {
                if (skuInfo.Cube > 0f)
                {
                    return ((decimal.Parse(obj.ToString()) - (decimal.Parse(skuInfo.Cube.ToString()) * genPutawayLocInfo.Qty)) >= 0M);
                }
                return true;
            }
            return false;
        }

        private bool SwitchLocStatusLimit(DataBase dataBase, DbTransaction tran, string suggestLoc, string locStatusLimit, bool isSelect, GenPutawayLocInfo genPutawayLocInfo, string whLoginID)
        {
            bool temp = true;
            if (string.IsNullOrEmpty(locStatusLimit))
            {
                return temp;
            }
            if (locStatusLimit != "10")
            {
                object obj = receiptDetailDA.CheckLocStatusLimitByPAStrategy(dataBase, tran, suggestLoc, locStatusLimit, whLoginID);
                string CS40002 = locStatusLimit;
                if (CS40002 == null)
                {
                    return temp;
                }
                if (!(CS40002 == "20"))
                {
                    DataSet ds;
                    if (CS40002 == "30")
                    {
                        if (isSelect)
                        {
                            return (((obj != null) && !string.IsNullOrEmpty(obj.ToString())) && (decimal.Parse(obj.ToString()) > 0M));
                        }
                        return true;
                    }
                    if (CS40002 == "40")
                    {
                        if ((obj != null) && !string.IsNullOrEmpty(obj.ToString()))
                        {
                            if (obj.ToString() == "N")
                            {
                                ds = receiptDetailDA.GetSkuOnLoc(dataBase, tran, suggestLoc, whLoginID);
                                if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
                                {
                                    return this.CheckIsMulitSkuCanPutAway2Loc(ds, genPutawayLocInfo, temp);
                                }
                                return true;
                            }
                            if (isSelect)
                            {
                                ds = receiptDetailDA.GetSkuOnLoc(dataBase, tran, suggestLoc, whLoginID);
                                if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
                                {
                                    return this.CheckIsMulitSkuCanPutAway2Loc(ds, genPutawayLocInfo, temp);
                                }
                                return true;
                            }
                            return true;
                        }
                        return false;
                    }
                    if (CS40002 != "50")
                    {
                        return temp;
                    }
                    if ((obj != null) && !string.IsNullOrEmpty(obj.ToString()))
                    {
                        if (obj.ToString() == "N")
                        {
                            ds = receiptDetailDA.GetLotOnLoc(dataBase, tran, suggestLoc, whLoginID);
                            if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
                            {
                                return this.CheckIsMulitLotCanPutAway2Loc(ds, genPutawayLocInfo, temp);
                            }
                            return true;
                        }
                        if (isSelect)
                        {
                            ds = receiptDetailDA.GetLotOnLoc(dataBase, tran, suggestLoc, whLoginID);
                            if ((ds != null) && (ds.Tables[0].Rows.Count > 0))
                            {
                                return this.CheckIsMulitLotCanPutAway2Loc(ds, genPutawayLocInfo, temp);
                            }
                            return true;
                        }
                        return true;
                    }
                    return false;
                }
                if (isSelect)
                {
                    if ((obj != null) && !string.IsNullOrEmpty(obj.ToString()))
                    {
                        return (decimal.Parse(obj.ToString()) == 0M);
                    }
                    return true;
                }
            }
            return true;
        }

        public string UpdateReceiptDetail(ReceiptDetailInfo receiptDetailInfo)
        {
            string whLoginID = this.dataBaseID[0];
            string LineID = string.Empty;
            try
            {
                receiptDetailInfo.CreatedDate = DateTime.Now;
                receiptDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                receiptDetailInfo.UpdatedDate = DateTime.Now;
                if (!string.IsNullOrEmpty(receiptDetailInfo.VendorID))
                {
                    IVendorDA vendorDA = DataAccess.CreateVendorDA();
                    if (!vendorDA.CheckVendorIDUnique(receiptDetailInfo.VendorID, this.dataBaseID[0]))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F4200_006", this.pubParasInfo.UserLanguage, new List<string> { receiptDetailInfo.VendorID });
                    }
                    else if (!vendorDA.CheckAuthorizationVendorIDUserID(receiptDetailInfo.VendorID, this.dataBaseID[0], this.pubParasInfo))
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F2130_002", this.pubParasInfo.UserLanguage, new List<string> { receiptDetailInfo.VendorID });
                    }
                }
                receiptDetailInfo.ExpectedQty = new InboundHelper().ExchangeUom(receiptDetailInfo.PackID, receiptDetailInfo.UomID, receiptDetailInfo.ExpectedQty, "W", whLoginID);
                ReceiptDetailInfo oldReceiptDetailInfo = receiptDetailDA.GetReceiptDetailByID(receiptDetailInfo.ReceiptID, receiptDetailInfo.ReceiptLineID.ToString(), this.dataBaseID[0], this.pubParasInfo);
                if (receiptDetailInfo.IsPalletized == "N")
                {
                    if (receiptDetailDA.UpdateReceiptDetail(receiptDetailInfo, whLoginID) > 0)
                    {
                        AuditDataBLL auditDataBLL = new AuditDataBLL();
                        auditDataBLL.InsertAuditData<ReceiptDetailInfo>(oldReceiptDetailInfo, receiptDetailInfo, AuditAction.Update, this.pubParasInfo.UserID, "RECEIPT_DETAIL", this.dataBaseID[0]);
                        LineID = receiptDetailInfo.ReceiptID + " , " + receiptDetailInfo.ReceiptLineID;
                    }
                    return LineID;
                }
                if (receiptDetailLpnDA.UpdateReceiptDetailLpn(receiptDetailInfo, whLoginID) > 0)
                {
                    new AuditDataBLL().InsertAuditData<ReceiptDetailInfo>(oldReceiptDetailInfo, receiptDetailInfo, AuditAction.Update, this.pubParasInfo.UserID, "RECEIPT_DETAIL_LPN", this.dataBaseID[0]);
                    LineID = receiptDetailInfo.ReceiptID + " , " + receiptDetailInfo.ReceiptLineID;
                }
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return LineID;
        }
    }
}

